Udostępnij za pośrednictwem


Adding SOAP Headers to Client Applications

SQL Server 2005 provides support for SOAP extension headers when you are using Native XML Web Services. These headers can be used to extend and enhance your SOAP-based applications by using SQL options and other SOAP extension headers that are supported, such as SOAP sessions and Web Services Security (WS-Security). For more information, see SOAP Extension Headers.

This topic features a sample class library that implements each optional SOAP extension headers that are supported by SQL Server 2005. This library can be added as to existing Visual Studio 2005 SOAP client projects. This includes the sample applications provided in Sample Applications for Sending Native XML Web Services Requests.

Additionally, we recommend the following topics if you are working with headers that implement either security or sessions support by using the appropriate SOAP extension headers for each of these features.

Note

The following procedure assumes that you have created an existing SOAP client application by using Visual Studio 2005 and have added a Web reference to an HTTP SOAP endpoint that was created by using SQL Server 2005, as shown in Sending SOAP Requests by Using Visual Studio 2005 Client (C#).

To add the SOAP extension header sample library to a Visual Studio project

  1. Using Notepad, copy and paste the contents of the C# Code Listing for the SQL SOAP Header Sample Class Library and save it with the name "SqlSoapHeader.cs" in the same folder that contains your SOAP client project files.

  2. On the client computer, from the Microsoft Visual Studio 2005 program group, start Microsoft Visual Studio 2005.

  3. Click Open Project.

  4. Browse and select your SOAP client project (.csproj) file.

  5. In the Solution Explorer window, follow these steps:

    1. Select the project by name, right-click and point to Add, and then select Add Existing Item.
    2. In the Add Existing Item dialog box, browse and select the SqlSoapHeader.cs file from the location you saved it to in step 1.
    3. Select Show All Files and expand the Web References node and select the Reference.cs file.
  6. In the Code Editor window, update the Reference.cs file to add a public variable to the endpoint definition class. The variable must be of the same SqlSoapHeader class as the type of SOAP optional header.

    For example, to add a public property variable called "sqlSecurity" of the SqlSoapHeader.Security class to the Reference.cs file under the endpoint class definition ("sql_endpoint"), you would add the following line of code:

    public class sql_endpoint : System.Web.Services.Protocols.SoapHttpClientProtocol {
         public SqlSoapHeader.Security  sqlSecurity
    
  7. Add the appropriate SoapHeaderAttribute property to the Web method that you want to enable the SOAP header for.

    For example, if you were implementing the Security class, you would add the following line of code:

    [System.Web.Services.Protocols.SoapHeaderAttribute("sqlSecurity")]
    public int UDFReturningAScalar() {...}
    

    Note

    In this example, the argument value sqlSecurity that is used with SoapHeaderAttribute must correspond to the variable name that was used in the previous step.

See Also

Reference

Setting the Server to Listen for Native XML Web Services Requests

Concepts

Best Practices for Using Native XML Web Services

Help and Information

Getting SQL Server 2005 Assistance