7

我在使用 webHttpBinding (soap 1.1) 的 WCF Web 服务中收到未设置为对象错误实例的对象引用我注意到,如果您以特定顺序输入参数,则不会引发错误。

IE

<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>

但是,如果我更改请求模板中输入参数的顺序,则会出现上述错误。ie(注意message和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>

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

4

2 回答 2

10

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

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

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

于 2014-06-26T05:38:55.757 回答
4

SOAP 消息的 XML 模式指定顺序。在元素的 XML 顺序中,WCF 正在根据架构验证 XML。

于 2012-07-26T11:40:29.990 回答