Web Services Quiz: Issue 1 – the Answer
The short answer to Issue 1 is int Add(int a, int b)
The first time I’d noticed this behavior, I was pretty surprised! Why should I get a cracked signature although the WSDL obviously would lead to the following signature?
AddResponseMsg Add(AddRequestMsg parameters)
The reason for this behavior is .NET’s support for Document Literal Wrapped encoding. This encoding allow developers to write [WebMethod] with signatures like the following:
int Add(int a, int b)
Document Literal encodings are message based and require the soap body to be described by an XML schema element. To fulfill this requirement for signatures like int Add(int a, int b)the .NET framework wrappes the parameters and the result to a request message and a response message. By the way, since these messages consist of the operation’s name, they can be used for rpc-style message dispatching as well.
Given the above example, the WSDL types, messages and port types look the following:
<types>
<s:schema elementFormDefault="qualified" targetNamespace="uri.test.com">
<s:element name="Add">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="i" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="j" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AddResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="AddResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<message name="AddSoapIn">
<part name="parameters" element="s0:Add" />
</message>
<message name="AddSoapOut">
<part name="parameters" element="s0:AddResponse" />
</message>
<portType name="EncodingTestSoap">
<operation name="Add">
<input message="s0:AddSoapIn" />
<output message="s0:AddSoapOut" />
</operation>
</portType>
The two wrappers Add and AddResponse were automatically generated to enable a “document-style” message exchange. You can apply the SoapDocumentService or SoapDocumentMethod attribute to explicitly specify your preferred parameter style:
[SoapDocumentService(
System.Web.Services.Description.SoapBindingUse.Literal,
SoapParameterStyle.Wrapped, // or SoapParameterStyle.Bare
RoutingStyle = SoapServiceRoutingStyle.SoapAction)]
But this is only one half of the story. The more interesting question is how wsdl.exe decides whether a bare or a wrapped style signature has to be generated. It makes this decision based on the WSDL message’s part name: If a part is named parameters, wsdl.exe applies the wrapped parameter style! <message name="AddSoapIn"> <part name="parameters" element="s0:Add" /> </message> |
- Anonymous
March 28, 2008
PingBack from http://countyanimalshelterblog.info/beat-schweglers-2-cents-web-services-quiz-issue-1-the-answer/