Beispiel für ein Dienstskript

In diesem Transact-SQL-Codebeispiel wird ein Dienst definiert, der nicht typisierte XML-Dokumente archiviert. Es schließt zwei Skripts ein: das Vertragsskript und das Dienstdefinitionsskript. Im Vertragsskript werden die Nachrichtentypen und der Vertrag für den Dienst definiert. Die Definition des Nachrichtentyps und die Vertragsdefinition sollten für den initiierenden Dienst und den Zieldienst identisch sein. Daher werden die Definitionen in ein separates Dienstdefinitionsskript aufgenommen, das an die Datenbanken verteilt werden kann, die den initiierenden Dienst hosten. Im Dienstdefinitionsskript wird der Dienst selbst definiert. Dieses Skript sollte nur in einer Datenbank ausgeführt werden, die den Zieldienst implementiert.

HinweisHinweis

Das Dienstdefinitionsskript definiert den Zieldienst, enthält aber keine Implementierung des Diensts.

Vertragsskript

-- 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

Dienstdefinitionsskript

-- 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