使用Create EndPoint创建本机XML Web Service

.Net 平台下的应用中,应用对内(外)的访问往往通过Web Service来实现,当然现在也可以使用WCF。大多数情况下,Web Service都是宿主在IIS上的,但是从SQL Server 2005起,我们可以在SQL Server 2005中发布本机XML Web Service,这样我们可以像访问宿主在IISWeb Service一样来访问SQL ServerXML Web Service

   注:在SQL Server 2008/R2中,已经不推荐使用本机XML Web Service,将会被WCFASP.Net所取代,在本文中只探讨如何定义和使用本机XML Web Service。参见:

http://msdn.microsoft.com/zh-cn/library/cc280436.aspx

虽然在SQL Server的未来版本中,本机XML Web Service将不存在,从技术爱好的角度来看,我们还是有必要了解一下这项技术,因为使用SQL Server 本机XML Web Service可以快速方便的把自定义函数或者存储过程转化为Web服务接口暴露出来。

要在SQL Server中实现本机XML Web Service,需要3个步骤:

1.       创建存储过程(已访问存储过程的Web Service方法为例), Create Procedure

2.       保留命名空间, sp_reserve_http_namespace

3.       创建访问端点,Create Endpoint

 

下面我们以微软的实例数据库AdventureWorks为例,把访问AddressType表的存储过程转化成Web Service,下面来详细说明。

1.创建存储过程

CREATE PROCEDURE dbo.PersonAddressTypeProc

    -- Add the parameters for the stored procedure here

AS

BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

 

    -- Insert statements for procedure here

    SELECT [AddressTypeID]

      ,[Name]

      ,[rowguid]

      ,[ModifiedDate]

 FROM [AdventureWorks].[Person].[AddressType]

END

GO

 

2.保留命名空间

sp_reserve_http_namespace N'http://localhost:80/AddressType'

这里我们将要创建的命名空间是:http://localhost/AddressType,如果没有执行sp_reserve_http_namespace,而去直接创建访问端点,那么会提示命名空间没有被创建或不存在。有关sp_reserve_http_namespace的更多内容可以访问:

http://msdn.microsoft.com/en-us/library/ms190614.aspx

 

4.       创建访问端点

5. Create Endpoint GetAddressType

6. State = Started

7. AS Http

8. (

9. path='/AddressType',

10. Authentication =(INTEGRATED),

11. ports =(CLEAR),

12. site ='localhost'

13.)

14.For SOAP

15.(

16. WebMetHod 'AddressTypeList'(Name ='AdventureWorks.dbo.PersonAddressTypeProc'),

17. Batches = disabled,

18. wsdl = default,

19. database ='AdventureWorks',

20. NAMESPACE = 'http://localhost:80/AddressType'

21.)

22.   GO

 

有关Create Endpoint的参数,感兴趣的读者可以参考:

http://msdn.microsoft.com/zh-cn/library/ms181591.aspx

 

在本文中,对语句及其参数并不做详细解释,有关详细解释大家可以参考《SQL SERVER 2005本机Web服务支持(实战篇)》,这里就不赘述了。下面给出完整代码:

-- ================================================

-- Template generated from Template Explorer using:

-- Create Procedure (New Menu).SQL

--

-- Use the Specify Values for Template Parameters

-- command (Ctrl-Shift-M) to fill in the parameter

-- values below.

--

-- This block of comments will not be included in

-- the definition of the procedure.

-- ================================================

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author:    <Author,,Name>

-- Create date: <Create Date,,>

-- Description:   <Description,,>

-- =============================================

CREATE PROCEDURE dbo.PersonAddressTypeProc

    -- Add the parameters for the stored procedure here

AS

BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

 

    -- Insert statements for procedure here

    SELECT [AddressTypeID]

      ,[Name]

      ,[rowguid]

      ,[ModifiedDate]

 FROM [AdventureWorks].[Person].[AddressType]

END

GO

 

sp_reserve_http_namespace N'http://localhost:80/AddressType'

     

Create Endpoint GetAddressType

    State = Started

AS Http

(

    path='/AddressType',

    Authentication =(INTEGRATED),

    ports =(CLEAR),

    site ='localhost'

)

For SOAP

(

    WebMetHod 'AddressTypeList'(Name ='AdventureWorks.dbo.PersonAddressTypeProc'),

    Batches = disabled,

    wsdl = default,

    database ='AdventureWorks',

    NAMESPACE = 'http://localhost:80/AddressType'

)

GO

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值