Ignoring Specifying SOAP Action

By default, the SOAP Action HTTP header value is generated by combining the Web service namespace with the operation (method) name. Also by default, .NET reads the SOAP Action value for each Web service request and uses it to determine which operation is to be invoked. Although this will work for most cases, you*re better off not relying on SOAP Action at all because it is a highly controversial topic in the SOAP world today.

At the time of this writing, the SOAP 1.2 W3C Working Draft states that SOAPAction is an optional feature and should not be required by a Web service unless there*s a particular purpose for doing so.

Listing 6-15 shows an example of setting the SoapDocumentServiceAttribute.RoutingStyle property to not rely on SOAPAction.

Listing 6-15 Specifying that requests are to be routed based on element name not SOAP Action

<SoapDocumentService( _

RoutingStyle:=SoapServiceRoutingStyle.RequestElement)> Public Class CustomWS

SoapDocumentService and SoapRpcService both have a RoutingStyle property which you can set to SoapServiceRoutingStyle.RequestElement to specify that the SOAP Action value should be ignored. Note that this property can only be set at the service level and not the method level.

If you use SoapServiceRoutingStyle.RequestElement with SoapParameterStyle.Bare parameter style, you must be careful about the number of parameters (must be exactly one) and parameter names for each Web method. That*s because you are telling .NET to route incoming messages to the corresponding methods based on the name of the child of the <soap: Body> element. At the same time you*re also telling it to include method parameters as direct children of <soap:Body> with no wrapper element. Although this can be tricky, .NET lets you get away with this combination provided that the method has exactly one parameter and that each method parameter is serialized to a different element name. .NET needs this restriction so it can tell which Web method to invoke based on the incoming element name. You*ll see an example of this combination in Chapter 13.

It*s also possible to set the required SOAP Action value for each method individually using the Action property of SoapRpcMethod or SoapDocumentMethod. Whatever string you specify as this property value becomes the soapAction attribute value in the WSDL SOAP binding section.

End Class

Listing 6-16 shows the completed CustomWS Web service with the Web methods and attributes discussed in this section.

Listing 6-16 The complete CustomWS Web service. (VBWSBook\Chapter6\CustomWS.asmx.vb)

<SoapDocumentService( _

RoutingStyle:=SoapServiceRoutingStyle.SoapAction) , _ WebService([Namespace]:="urn:my-unique-namesp ace", _ Name:="MyWeb.Service", _

Description:="Example of customizing Web services. " + _ "Written by <a href='mailto:[email protected]'>Yasser Shohoud</a>")> _ Public Class CustomWS Inherits System.Web.Services.WebService

<WebMethod( _ Description:="This method has a custom operation name", _ MessageName:="My.Message")> _ Public Function CustomMsgName() As Integer

End Function

SoapDocumentMethod(RequestNamespace:="http:/ /xmlws.com/messages")> _ Public Function CustomNS() As Integer

End Function

SoapDocumentMethod(ParameterStyle:=SoapParameterStyle.Bare)> _ Public Function ParamStyleTest( _

ByVal a As Integer, ByVal b As String)_ As String

End Function

<WebMethod(), SoapDocumentMethod(OneWay:=Tr ue)> _ Public Sub OneWayMethod(ByVal theData As String)

End Sub End Class

Now that you know how to create and customize Web services, the next section explains how .NET Web service clients work and how you can customize them to meet your needs.

A Web service proxy class inherits from either HttpGetClientProtocol, HttpPostClientProtocol, or SoapHttpClientProtocol depending on whether it uses HTTP GET, HTTP POST or SOAP to invoke the Web service. As I mentioned earlier, HTTP GET and POST a re somewhat interesting for quickly testing the service, but any real-world Web service will likely use SOAP which means the Web service proxy will inherit from SoapHttpClientProtocol. Figure 6-13 shows the class hierarchy for a Web service proxy, note that SoapHttpClientProtocol inherits from HttpWebClientProtocol which in turn inherits from WebClientProtocol.

+1 0


  • jussi
    How to set soapaction webservice vb.net?
    5 years ago

Post a comment