Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
SQL Server
Azure SQL Managed Instance
This Transact-SQL code sample defines a service that archives untyped XML documents. Two scripts are included: the contract script and the service-definition script. The contract script defines the message types and the contract for the service. The message-type definition and the contract definition should match for both the initiating service and the target service. Therefore, the definitions are included in a separate service-definition script that can be distributed to the databases that host the initiating service. The service-definition script defines the service itself. This script should be run only in a database that implements the target service.
Note
The service-definition script defines the target service, but doesn't include an implementation of the service.
Contract script
Note
The code samples in this article were tested using the AdventureWorks2025 sample database, which you can download from the Microsoft SQL Server Samples and Community Projects home page.
-- The contract script contains definitions that must be present
-- for both the initiating 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
Service definition script
-- 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