Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF and Input Parameter Order in SOAP Envelope

I'm getting an Object reference not set to an instance of object error in my WCF web service which uses webHttpBinding (soap 1.1) I have noticed that if you have the input parameters in a certain order the error does not get raised.

i.e.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://schemas.globalfoundries.com/NotificationService">
   <soapenv:Header/>
   <soapenv:Body>
      <not:NotifyWorkflowItemUpdate>
         <not:userIDs>testUserID</not:userIDs>
         <not:taskID>testTaskID</not:taskID>
         <not:taskType>testTaskType</not:taskType>
         <not:status>testStatus</not:status>
         <not:appID>testAppID</not:appID>
         <not:message>testMessage</not:message>
      </not:NotifyWorkflowItemUpdate>
   </soapenv:Body>
</soapenv:Envelope>

However if I change the order of the input parameters in the request template I get the aforementioned error. i.e. (note message and userIDs parameters are switched)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://schemas.globalfoundries.com/NotificationService">
   <soapenv:Header/>
   <soapenv:Body>
      <not:NotifyWorkflowItemUpdate>
     <not:message>testMessage</not:message>
         <not:taskID>testTaskID</not:taskID>
         <not:taskType>testTaskType</not:taskType>
         <not:status>testStatus</not:status>
         <not:appID>testAppID</not:appID>
         <not:userIDs>testUserID</not:userIDs>
      </not:NotifyWorkflowItemUpdate>
   </soapenv:Body>
</soapenv:Envelope>

Why is this happening? Are request parameters mapped to the .Net method parameters via the order and not by the names? Is there an attribute that I have to specify on the service contract to make named parameter mapping possible?

like image 286
Harindaka Avatar asked Jul 26 '12 10:07

Harindaka


People also ask

Does order matter in SOAP request?

The order of the parameters in the generated Java code does not matter, what matters is the contents of the SOAP request message.

Is it possible to customize SOAP message in WCF name the WCF technique used to achieve the customization?

Creating a custom Message Object with WCF In order to customize the message, three classes are needed: Message Class. ClientMessageFormatter Class. FormatMessageAttribute Class.

What is the message format of SOAP protocol?

A SOAP message is encoded as an XML document, consisting of an <Envelope> element, which contains an optional <Header> element, and a mandatory <Body> element. The <Fault> element, contained in <Body> , is used for reporting errors.

Where is the payload for the SOAP message?

SOAP uses XML to express payload information accurately and concisely. Every SOAP message has a main envelope section, which can contain header and body sub-sections.


2 Answers

You need to use XmlSerializerFormat class in your WCF service interface.

[ServiceContract, XmlSerializerFormat]
public interface IGoodMessageService
{
    ...
}

Problem and solution is explained in this link: http://neimke.blogspot.com.tr/2012/03/serialization-ordering-causes-problems.html

like image 89
İsmail ÇAĞDAŞ Avatar answered Oct 24 '22 06:10

İsmail ÇAĞDAŞ


The XML schema of your SOAP message specifies the order. In XML order of element matters and WCF is validating the XML against the schema.

like image 21
softveda Avatar answered Oct 24 '22 05:10

softveda