Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Bindings in WSDL

Bindings provide a method for WSDL to bind operations and ports to protocols. The basic format for this is given below:

<wsdl:binding name="nmtoken" type="qname"> *
  <wsdl:operation name="nmtoken"> *
   <wsdl:input name="nmtoken"? > ?
   <wsdl:output name="nmtoken"? > ?
   <wsdl:fault name="nmtoken"> *

In the previous code, name is a unique identifier for the particular binding and type is the name of the portType being bound. Typically, Visual Studio.NET will simply use the portType name as the identifier in name.

SOAP Bindings

Listing 3.5 shows a binding for a SOAP port. The port was named DatTypesSoap, and thus, the binding is named this as well. As you can see, the binding binds the portType, DataTypesSoap to the SOAP transport protocol, line 2. Furthermore, each operation—StringReturn in this example—has its input, output, and (optionally) its fault messages further defined.

Listing 3.5 Binding a SOAP portType to the SOAP Protocol

1:  <binding name="DataTypesSoap" type="s0:DataTypesSoap">
2:   <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
3:          style="document" />
4:   <operation name="StringReturn">
5:    <soap:operation soapAction="http:\http://www.myServer.com\DataTypes/StringReturn"
6:            style="document" />
7:    <input>
8:     <soap:body use="literal" />
9:    </input>
10:   <output>
11:     <soap:body use="literal" />
12:   </output>
13:  </operation>
14: </binding>


Since XML Web services must deal with client applications other than those utilizing SOAP protocols, WSDL supports bindings for both HttpGet and HttpPost. As with SOAP, HttpGet bindings bind the portType, DataTypesHttpGet in Listing 3.6, to the HttpGet protocol.

The most important detail here is the specifics of transports for each message. Input communications are set to use the urlEncoding method, line 6, whereas outbound information will be presented as the body of an HTML document (line 9).

Listing 3.6 Binding an HttpGet portType to the Get Protocol

1:  <binding name="DataTypesHttpGet" type="s0:DataTypesHttpGet">
2:   <http:binding verb="GET" />
3:   <operation name="StringReturn">
4:    <http:operation location="/StringReturn" />
5:    <input>
6:     <http:urlEncoded />
7:    </input>
8:    <output>
9:     <mime:mimeXml part="Body" />
10:   </output>
11:  </operation>
12:  </binding>


Listing 13.7 shows the binding for an HttpPost operation. This binding is very similar to that used by HttpGet. Of note here is the use of the HttpPost method of passing arguments as Form data instead of encoded data in the requesting URL, line 6.

Listing 3.7 Binding an HttpPost portType to the Post Protocol

1:  <binding name="DataTypesHttpPost" type="s0:DataTypesHttpPost">
2:   <http:binding verb="POST" />
3:   <operation name="StringReturn">
4:    <http:operation location="/StringReturn" />
5:    <input>
6:     <mime:content type="application/x-www-form-urlencoded" />
7:    </input>
8:    <output>
9:     <mime:mimeXml part="Body" />
10:    </output>
11:  </operation>
12: </binding>
  • + Share This
  • 🔖 Save To Your Account