SOAP 信封中的 WCF 和输入参数顺序 [英] WCF and Input Parameter Order in SOAP Envelope

查看:20
本文介绍了SOAP 信封中的 WCF 和输入参数顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

但是,如果我更改请求模板中输入参数的顺序,则会出现上述错误.即(注意 message 和 userIDs 参数被切换)

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>

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

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?

推荐答案

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

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

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

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

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

这篇关于SOAP 信封中的 WCF 和输入参数顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆