Share via


使用自訂 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 部份:設定伺服器

  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. 執行指令碼。

第 2 部份:測試處理常式

若要確定自訂 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 Service 的最佳作法

說明及資訊

取得 SQL Server 2005 協助