Using nested complex types in SOAP Message - WCF XmlSerializer

拜拜、爱过 提交于 2019-12-23 03:59:10

问题


I recently posted a question on StackOverflow:

SOAP message deserialization issue in WCF - fields have null values

It was something about one of the WCF serialization engines, XmlSerializer, used to serialize/deserialize SOAP messages. The deserialization didn't work at first - some namespace issues.

Back to present :)

Fields decorated with [XmlElement, MessageBodyMember] are deserialized fine now if they are simple types.

There is a problem regarding custom types: they are set, but their fields have null values :(

Is there a configuration I should make on the XmlSerializer?

[MessageContract]
public class Request
{
    [XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified), MessageBodyMember]
    public XType X { get; set; }
}

[what to write here?]
public class XType
{
    [XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified), body member?]
    public string AString { get; set; }

    ... maybe another nested complex objects
}

回答1:


I had those serialization problems because the client of the service has a serialization engine that is not "compatible" with the ones that WCF uses. The request was still standard XML, of course (SOAP 1.2), but hey, WCF is a Microsoft product :)

Some workarounds:

  • Add a MessageFormater - that implements some deserialization logic at the server side - a good article about that;
  • Add a MessageInspector - that reads the SOAP request and does some XML formatting (so that the deserialization will work fine) - you can read about it following this link.


来源:https://stackoverflow.com/questions/11758380/using-nested-complex-types-in-soap-message-wcf-xmlserializer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!