turdus-merula
turdus-merula

Reputation: 8854

Using nested complex types in SOAP Message - WCF XmlSerializer

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
}

Upvotes: 1

Views: 2019

Answers (1)

turdus-merula
turdus-merula

Reputation: 8854

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.

Upvotes: 1

Related Questions