4 Protocol Examples

The following is an example of a procedure with which clients can use this protocol to create a simple database and then populate it with data.

First, the client begins by invoking the BeginPublish operation together with the valid server connection and user credentials, as shown in the following code example.

SOAP 1.1 BeginPublish Request

 POST /Database%20Publsihing%20Services%201.1/Publish/Service.asmx HTTP/1.1
 Host: localhost
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 SOAPAction: "http://schemas.microsoft.com/sqlserver/2006/12/publishing/BeginPublish"
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <BeginPublish 
 xmlns="http://schemas.microsoft.com/sqlserver/2006/12/publishing">
       <serverName>myServer</serverName>
       <databaseName>myDatabase</databaseName>
       <sqlUsername>myUsername</sqlUsername>
       <sqlPassword>myPassword</sqlPassword>
       <useTransactions>true</useTransactions>
     </BeginPublish>
   </soap:Body>
 </soap:Envelope>

SOAP 1.1 BeginPublish Response

 HTTP/1.1 200 OK
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <BeginPublishResponse 
 xmlns="http://schemas.microsoft.com/sqlserver/2006/12/publishing" />
   </soap:Body>
 </soap:Envelope>

Then, the client invokes the PublishScript operation with a Transact-SQL script, which creates the new database and the database objects (for example, tables, views, and stored procedures), as shown in the following code example.

SOAP 1.1 PublishScript Request

 POST /Database%20Publsihing%20Services%201.1/Publish/Service.asmx HTTP/1.1
 Host: localhost
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 SOAPAction: "http://schemas.microsoft.com/sqlserver/2006/12/publishing/PublishScript"
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <PublishScript 
 xmlns="http://schemas.microsoft.com/sqlserver/2006/12/publishing">
       <script>create table table1(id int primary key)</script>
     </PublishScript>
   </soap:Body>
 </soap:Envelope>

SOAP 1.1 PublishScript Response

 HTTP/1.1 200 OK
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <PublishScriptResponse 
 xmlns="http://schemas.microsoft.com/sqlserver/2006/12/publishing" />
   </soap:Body>
 </soap:Envelope>

Lastly, the client invokes the EndPublish operation to finish the publishing session and to release server resources, as shown in the following code example.

SOAP 1.1 EndPublish Request

 POST /Database%20Publsihing%20Services%201.1/Publish/Service.asmx HTTP/1.1
 Host: localhost
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 SOAPAction: "http://schemas.microsoft.com/sqlserver/2006/12/publishing/EndPublish"
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <EndPublish 
 xmlns="http://schemas.microsoft.com/sqlserver/2006/12/publishing" />
   </soap:Body>
 </soap:Envelope>

SOAP 1.1 EndPublish Response

 HTTP/1.1 200 OK
 Content-Type: text/xml; charset=utf-8
 Content-Length: length
 <?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <EndPublishResponse 
 xmlns="http://schemas.microsoft.com/sqlserver/2006/12/publishing" />
   </soap:Body>
 </soap:Envelope>