Examples of Using SOAP Interface with the SQL Data Services
[This document supports a preliminary release of a software product that may be changed substantially prior to final commercial release. This document is provided for informational purposes only.]
You can use the SOAP or REST interfaces to develop applications with the Microsoft® SQL Data Services (SDS). The following topics provide examples that use the SOAP interface:
Creating an Authority Using SOAP
Creating a Container Using SOAP
Deleting a Container Using SOAP
Retrieving and Updating an Entity Using SOAP
Querying and Deleting Entity Using SOAP
Follow these steps to create working samples:
- Start the Microsoft Visual Studio integrated development environment, and then create a console application.
- Add a reference to
System.ServiceModel
. - To be able to send SOAP requests, you need to add a
service reference
to your project. There are differences in how you add a service reference in Visual Studio 2005 and in Visual Studio 2008.
Adding Service Reference in Visual Studio 2008
- Click Add Service Reference from the project menu.
- Specify address
https://database.windows.net/soap/v1/
. - Change the default value (
ServiceReference1
) forNamespace
tossdsClient
. - Some of the samples use generic List (not Array). You will need to update the service reference settings. Click Advanced.
- In the Service Reference Settings dialog box, in Collection Type, click System.Collections.Generic.List, and then click OK.
- Enter the code, and then build and run the application.
Adding Service Reference in Visual Studio 2005
There are two ways to add a service reference in Visual Studio 2005:
- Command line (svcutil.exe)
- Using the Visual Studio graphical user interface
Both these approaches are described below:
Adding Service Reference at the Command Line (Visual Studio 2005)
Ensure you have following components installed (in order).
- Visual Studio 2005
- Visual Studio 2005 SP1
- .NET Framework 3.0 Runtime Components
- .NET Framework 3.0 SDK
To add a service reference, you first run svcutil.exe at the command prompt to generate the ssdsClient.cs and app.config files. You add these files to your project.
Note
The svcutil.exe program is usually found in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\svcutil.exe
, but it may also be located in the directory where the SDK is installed, which is probably something like C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\svcutil.exe
depending on which version of the SDK you installed and whether you specified a different directory during the installation. The SDK version of this program is more current. Both will produce identical output for our purposes.
At the command prompt, run svcutil.exe. The ^ symbols below are added to simplify cut and paste in a command window. They are not actually part of the command syntax. Furthermore, you must provide the project namespace that you created with your Visual Studio project in the place indicated:
svcutil.exe /noLogo /out:"ssdsClient.cs" /language:csharp ^ /config:app.config ^ /n:*,<ProjectNamespace>.ssdsClient ^ /serializable ^ /ser:DataContractSerializer ^ /importXmlTypes ^ https://database.windows.net/soap/v1/
This command generates the
ssdsClient.cs
andapp.config
files.Add these files to your project. If the project already has an
app.config
(or a<program-name>.exe.config)
file, then manually merge the content of the newapp.config
file in to your existingapp.config
.Add a reference to the .NET Framework assembly (
System.ServiceModel, 3.0.0.0
)Add a reference to
System.Runtime.Serialization
.Add the following using statement at the beginning of your code.
using <ProjectName>.ssdsClient;
Adding Service Reference Using GUI (Visual Studio 2005)
Follow these steps to add a service reference using Visual Studio 2005 graphical user interface. In order to follow along with the examples as documented, an additional step is required (documented as step #5). This step is required as several of the examples use the List<T> for return types.
NOTE: These generated code modifications are not required if you choose to generate the service proxy from the command line as documented earlier.
- Right-click References, and then click Add Service Reference
- In the Service URI text box, enter
https://database.windows.net/soap/v1/
. - Change Service reference name to
ssdsClient.
- Click OK.
- Some of the samples use the List class instead of the Array class, and so you will need to modify ssdsClient.cs under Service References/ssdsClient.map.
Change in public interface
ISitkaSoapService
fromYourNameSpace.ssdsClient.Entity[] Query(YourNameSpace.ssdsClient.Scope scope, [System.ServiceModel.MessageParameterAttribute(Name="query")] string query1);
to
List<YourNameSpace.ssdsClient.Entity> Query(YourNameSpace.ssdsClient.Scope scope, [System.ServiceModel.MessageParameterAttribute(Name="query")] string query1);
Change query method inside public partial class
SitkaSoapServiceClient
frompublic YourNameSpace.ssdsClient.Entity[] Query(YourNameSpace.ssdsClient.Scope scope, string query1)
to
public List< YourNameSpace.ssdsClient.Entity> Query(YourNameSpace.ssdsClient.Scope scope, string query1)
Endpoint names
When interacting with SDS using the SOAP interface, both the basic authentication and token-based authentication schemes are supported. For information on using token-based authentication scheme, see SDS and .NET Access Control Service Integration.
Depending on the authentication scheme you use, appropriate endpoint name must be specified when creating a SOAP client. SOAP samples provided in this topic use basic authentication for which the endpoint name is BasicAuthEndpoint
.
See Also
Concepts
Getting Ready to Use SQL Data Services
Examples of Using REST Interface with the SQL Data Services