node-soap icon indicating copy to clipboard operation
node-soap copied to clipboard

Response parsing fails if message names don't match operation names

Open darrenderidder opened this issue 14 years ago • 2 comments

In the RPC/literal style, the SOAP request message body contains an element named after the operation being called (for example, 'getUserID'), and the response body contains an element named after the operation with 'Response' appended (i.e. 'getUserIDResponse'). This is described in Section 2.4.5 of the WSDL 1.1 Specification (http://www.w3.org/TR/wsdl#_names).

This is confusing because in most examples the response name of the element in the response body matches the name of the output message.

// Typical WSDL fragment
<message name="getUserIDResponse"...
// SOAP response fragment
<env:Body>
    <ns0:getUserIDResponse xmlns:ns0='http://mycoolsite.com/services/userapi'>
        <return>
            <item>169085696</item>
        </return>
        ...

Some frameworks (like JBOSS) try to be clever when they generate a WSDL by prefixing the portType name to the message names with an underscore (i.e. MyAPI_getUserIDResponse).

// JBOSS auto-generated WSDL fragment
<message name="MyAPI_getUserIDResponse"...
...
<portType name="MyAPI">
    <operation name="getUserID" ... >
        <input .../>
        <output message="tns:MyAPI_getUserIDResponse"/>
    </operation>
// SOAP response for the above
// same as before, note Body contains a getUserIDResponse element whose name 
// is a combination of the operation + 'Response' as per WSDL 1.1 section 2.4.5
// This does *not* match the defined MyAPI_getUserIDResponse message name
<env:Body>
    <ns0:getUserIDResponse xmlns:ns0='http://mycoolsite.com/services/userapi'>
        <return>
            <item>169085696</item>
        </return>
        ...

Unfortunately the node-soap WSDL parser assumes that messages will be named using the same convention as SOAP message bodies. If a SOAP response body contains a 'getUserIDResponse' element (operation name + 'Response'), it expects a message named 'getUserIDResponse' to have been defined as well. But if the WSDL has defined the message with a different naming convention, the response parsing fails because there's no message named "getUserIDResponse".

Ideally, when a response such as getUserIDResponse is received, the portTypes should be searched for an operation named 'getUserID' (the 'Response' suffix removed). The matching method's ouput name will contain the correct message ntoken to use (i.e. MyAPI_getUserIDResponse). This name can then be used to look up the message definition. A mapping of operation input and output names to message names would support this naming abstraction.

Additional references:

  • http://www.ibm.com/developerworks/webservices/library/ws-tip-namespace/index.html
  • http://msdn.microsoft.com/en-us/library/ms996466.aspx
  • http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/

darrenderidder avatar Apr 25 '12 22:04 darrenderidder

@darrenderidder Thanks for your fix. I merged in your pull request that solves this issue.

milewise avatar Apr 30 '12 21:04 milewise

thanks for the merge. the module has been working really well. much appreciated.

darrenderidder avatar May 01 '12 15:05 darrenderidder