서비스 스크립트 예

Transact-SQL 코드 예제에서는 형식화되지 않은 XML 문서를 보관하는 서비스를 정의합니다. 여기에는 계약 스크립트와 서비스 정의 스크립트라는 두 개의 스크립트가 포함됩니다. 계약 스크립트는 서비스의 메시지 유형과 계약을 정의합니다. 메시지 유형 정의와 계약 정의는 시작 서비스와 대상 서비스 모두에 대해 일치해야 합니다. 따라서 이러한 정의는 시작 서비스를 호스팅하는 데이터베이스에 배포할 수 있는 별도의 서비스 정의 스크립트에 포함됩니다. 서비스 정의 스크립트는 서비스 자체를 정의합니다. 이 스크립트는 대상 서비스를 구현하는 데이터베이스에서만 실행할 수 있습니다.

[!참고]

서비스 정의 스크립트는 대상 서비스를 정의하지만 해당 서비스의 구현은 포함하지 않습니다.

계약 스크립트

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

참고 항목

개념