SOAP信封中的WCF和输入参数顺序

Har*_*aka 5 wcf soap request input-parameters

我在我的WCF Web服务中使用webHttpBinding(soap 1.1)得到一个Object引用未设置为对象错误的实例我注意到如果你按照特定顺序输入参数,则不会引发错误.

<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>
Run Code Online (Sandbox Code Playgroud)

但是,如果我更改请求模板中输入参数的顺序,我会得到上述错误.ie(注意消息和userIDs参数被切换)

<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>
Run Code Online (Sandbox Code Playgroud)

为什么会这样?请求参数是否通过订单而不是名称映射到.Net方法参数?是否有必须在服务合同上指定的属性才能使命名参数映射成为可能?

İsm*_*DAŞ 7

您需要在WCF服务接口中使用XmlSerializerFormat类.

[ServiceContract, XmlSerializerFormat]
public interface IGoodMessageService
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

此链接解释了问题和解决方案:http://neimke.blogspot.com.tr/2012/03/serialization-ordering-causes-problems.html


sof*_*eda 5

SOAP 消息的 XML 架构指定了顺序。在 XML 中,元素顺序很重要,WCF 正在根据架构验证 XML。