共用方式為


服務指令碼範例

這個 Transact-SQL 程式碼範例會定義服務,以封存不具類型的 XML 文件。包括兩個指令碼:「合約指令碼」(Contract Script) 以及「服務定義指令碼」(Service Definition Script)。合約指令碼會定義訊息類型與服務的合約。訊息類型定義與合約定義應該符合起始服務與目標服務。因此,這些定義是包括在個別的服務定義指令碼中,而這個指令碼可以散發到主控起始服務的資料庫。服務定義指令碼會定義服務本身。這個指令碼應該只能在實作目標服務的資料庫中執行。

[!附註]

服務定義指令碼會定義目標服務,但是不包括服務的實作。

合約指令碼

-- The contract script contains definitions that must be
-- present for both the intiating service and the target
-- service.

USE AdventureWorks2008R2;
GO

-- Create messages for each broker-to-broker
-- communication needed to complete the task.

-- Message for the initiator to send XML
-- to be archived.

CREATE MESSAGE TYPE
    [//Adventure-Works.com/messages/ArchiveXML]
    VALIDATION = WELL_FORMED_XML ;
GO

-- Message to return event archiving information.

CREATE MESSAGE TYPE
    [//Adventure-Works.com/messages/AcknowledgeArchiveXML]
    VALIDATION = WELL_FORMED_XML ;
GO

-- Create a service contract to structure
-- an event archiving conversation, using 
-- the message types defined above.

CREATE CONTRACT 
    [//Adventure-Works.com/contracts/ArchiveXML/v1.0]
    (
        [//Adventure-Works.com/messages/ArchiveXML]
        SENT BY INITIATOR,
        [//Adventure-Works.com/messages/AcknowledgeArchiveXML]
        SENT BY TARGET
     ) ;
GO

服務定義指令碼

-- This script defines the target service. The
-- objects created by this script are only
-- required in a database that hosts the target
-- service.

USE AdventureWorks2008R2 ;
GO

-- Create the service queue that will receive 
-- messages for conversations that implement
-- the ArchiveXML contract.

CREATE QUEUE ArchiveQueue ;
GO

-- Create the service object that exposes the 
-- ArchiveEvents service contract and maps 
-- it to the ArchiveQueue service queue.

CREATE SERVICE [//Adventure-Works.com/ArchiveService]
    ON QUEUE ArchiveQueue
    ([//Adventure-Works.com/contracts/ArchiveXML/v1.0]) ;
GO

請參閱

概念