使用自定义 WSDL 应用程序

若要设置自定义的 WSDL 生成器示例应用程序,您必须执行以下任务:

  • 创建自定义的 WSDL 处理程序以支持特定的 WSDL。
    若要完成此任务,请参阅生成自定义 WSDL 应用程序
  • 配置 SQL Server 2005 的安装以注册并使用自定义的 WSDL 处理程序。

此任务涉及创建部署脚本,用以对 SQL Server 2005 的安装进行以下修改:

  • 将自定义的 WSDL 程序集 (CustomWSDL.dll) 添加到服务器上并进行注册,以便与 ADD ASSEMBLY 语句一起使用。
  • 创建自定义的 WSDL 处理程序进行正确操作所需要的其他存储过程。
  • 在 SQL Server 实例上创建或修改 HTTP 端点,使其使用自定义的 WSDL 处理程序并返回自定义的 WSDL 响应,而不是返回默认响应或简单的 WSDL 响应。

部署自定义的 WSDL 处理程序

以下过程假设在运行 SQL Server 2005 的计算机上您作为本地管理员登录,或您能以管理权限远程连接到此计算机。

第一部分:配置服务器

  1. 在 SQL Server Management Studio 中,单击**“新建查询”**并连接到服务器。

  2. 将以下 Transact-SQL 脚本复制到查询窗口。

    USE master 
    GO
    
    -- Drop myWSDL procedure if it exists.
    IF (SELECT count(*) FROM sysobjects WHERE name = 'myWSDL') = 1 
    DROP PROCEDURE myWSDL
    GO
    
    -- Drop CustomWSDL assembly if it exists.
    DROP ASSEMBLY CustomWSDL
    GO
    
    -- Update the path to the compiled assembly as necessary.
    CREATE ASSEMBLY CustomWSDL FROM 'C:\temp\CustomWSDL.dll'
    GO 
    
    -- Create a stored procedure to map to the common lanugage
    -- runtime (CLR) method As with any other SQL Server stored procedure
    -- that maps to a CLR method, the actual stored procedure name 
    -- ('myWSDL') can be arbitrarily specified.
    CREATE PROCEDURE myWSDL
    (
    @endpointID as int,
    @isSSL as bit,
    @host as nvarchar(256),
    @queryString as nvarchar(256),
    @userAgent as nvarchar(256)
    )
    AS EXTERNAL NAME CustomWSDL.[MSSql.CustomWSDL].GenerateWSDL
    GO
    
    -- Follow the security guidelines set up for your environment.
    -- The following example is meant to be used for development or 
    -- testing purposes only.
    GRANT EXEC on myWSDL to [PUBLIC]
    GO
    
    -- The following is a sample stored procedure (InOut) that
    -- demonstrates the configuration of an HTTP endpoint. 
    -- If the InOut stored procedure already exists, it is dropped.
    IF (SELECT count(*) FROM sysobjects WHERE name = 'InOut') = 1 DROP PROC InOut
    GO
    
    CREATE PROC InOut
             @InParam int,
             @OutParam nvarchar(100) output
    AS
    SELECT * FROM syslanguages WHERE langid = @InParam
    SELECT @OutParam = [name] FROM syslanguages WHERE langid = @InParam
    PRINT @OutParam
    SELECT * FROM syslanguages WHERE langid = @InParam FOR XML raw, XMLSCHEMA
    RETURN 1
    GO
    GRANT EXEC on InOut to [PUBLIC]
    
    -- The following creates a sample HTTP endpoint to demonstrate 
    -- the endpoint setup. If the sample endpoint already exists, it
    -- is first dropped.
    IF (SELECT count(*) FROM [msdb].sys.http_endpoints WHERE name = 'sql_endpoint') = 1
    DROP ENDPOINT sql_endpoint
    GO
    
    CREATE ENDPOINT sql_endpoint
             STATE=STARTED
    AS HTTP (
             SITE='*',
             PATH='/sql/WSDL',
             PORTS=(CLEAR),
             CLEAR_PORT=80,
             AUTHENTICATION=(DIGEST, INTEGRATED)
    )
    FOR SOAP
    (
             WEBMETHOD 'http://myNS.com/'.'InOut' ( NAME='master.dbo.InOut' ),
             DATABASE = 'master',
             WSDL='master.dbo.myWSDL',
             Batches=enabled,
             SCHEMA = STANDARD
    )
    
    GRANT CONNECT ON ENDPOINT::sql_endpoint to [PUBLIC]
    
  3. 执行脚本。

第二部分:测试处理程序

若要确保自定义的 WSDL 处理程序运行正常,请尝试使用修改过的 URL 查询字符串来请求自定义的 WSDL。例如,如果您正与之建立连接的 SQL Server 2005 实例命名为 MyServer 并且使用了以前的脚本,则它应该具有在 sql/WSDL 服务器上建立的端点路径,使用自定义的 WSDL 处理程序将响应该服务器。因此,若要测试连接到此端点并提供自定义的 WSDL 请求,您应使用以下 HTTP Web 浏览器客户端中的 URL:

http://MyServer/sql/WSDL?wsdlargument

argument 的值可以是以下自定义的 WSDL 标识符的任意一个,这些标识符支持每一不同客户端和 WSDL 类型的字符串。

自定义的 WSDL URL 说明

everett

用于使用 Visual Studio 2003 开发工具开发的简单 Web 客户端。

jbuilder

用于使用 Borland JBuilder 9.0 开发工具开发的简单 Web 客户端。

glue

用于使用 webMethods Glue 5.0.1 开发工具开发的简单 Web 客户端。

如下表所示,<argument> 值为所有三个自定义选择返回了简单的 WSDL(所有 XSD 本机类型);但是,如果您想要完整扩展的 WSDL,您可以将 extended 追加到查询参数字符串。

简单的 WSDL 标识符 扩展的 WSDL 标识符

http://MyServer/sql/WSDL?wsdleverett

http://MyServer/sql/WSDL?wsdleverettextended

http://MyServer/sql/WSDL?wsdljbuilder

http://MyServer/sql/WSDL?wsdljbuilderextended

http://MyServer/sql/WSDL?wsdlglue

http://MyServer/sql/WSDL?wsdlglueextended

请参阅

任务

自定义 WSDL 应用程序的 C# 代码列表

参考

实现自定义 WSDL 支持
生成自定义 WSDL 应用程序

概念

使用本机 XML Web 服务的最佳方法

帮助和信息

获取 SQL Server 2005 帮助