WCF消息体反序列化期望任意名称空间

时间:2018-01-23 17:49:04

标签: c# xml wcf soap deserialization

我有一个WCF服务应该能够接收基于HTNG / OTA出版物(标准?)的SOAP消息。这个出版物包含了大量的.xsd文件,我用它来自using Visual Studio's XSD as type definition feature自动生成类(合同?)。

此生成的类如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("MSBuild", "15.5.180+ge4c819961e")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.opentravel.org/OTA/2003/05")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.opentravel.org/OTA/2003/05", IsNullable=false)]
public partial class OTA_HotelResNotifRQ
{ ... }

然后我设置了一个非常简单的服务方法,该方法应该接收包含OTA_HotelResNotifRQ作为有效负载的SOAP消息,如:

// interface    
[OperationContract(Action = "OTA_HotelResNotifRQ", ReplyAction = "OTA_HotelResNotifRS")]
Message HotelResNotifRQ(Message input);

// implementation
public Message HotelResNotifRQ(Message input)
{
    var body = input.GetBody<OTA_HotelResNotifRQ>();
    // do something
}

GetBody&lt;&gt;调用它应该反序列化消息的正文,但最终会抛出异常:

  

第16行位置错误293.期待元素'OTA_HotelResNotifRQ'   从命名空间   'http://schemas.datacontract.org/2004/07/My.Projects.Namespace' ..   遇到'Element',名称为'OTA_HotelResNotifRQ',名称空间   'http://www.opentravel.org/OTA/2003/05'。

所以我得到了一个命名空间不匹配,但是那里的 schemas.datacontract.org 的任意命名空间来自哪里,为什么它忽略了该类型的Xml序列化属性中设置的命名空间( OTA_HotelResNotifRQ )本身?

我如何告诉它 OTA_HotelResNotifRQ 确实来自opentravel命名空间?

0 个答案:

没有答案