我在使用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>
但是,如果我更改请求模板中输入参数的顺序,则会收到上述错误。即(注意消息和用户ID参数已切换)
<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方法参数?我必须在服务契约(Contract)上指定一个属性以使命名参数映射成为可能吗?
最佳答案
您需要在WCF服务界面中使用 XmlSerializerFormat 类。
[ServiceContract, XmlSerializerFormat]
public interface IGoodMessageService
{
...
}
在此链接中说明问题和解决方案:http://neimke.blogspot.com.tr/2012/03/serialization-ordering-causes-problems.html
关于wcf - SOAP信封中的WCF和输入参数顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11667771/