How to use XML attribute in MessageContract type?

Before recording: I cannot change the format of incoming SOAP requests, as they are captured by international standards (weeeeeeeee).

I have a SOAP request that goes into my WCF service, looking something like this:

<s:Body>
    <Request version="1.0">
        <data someOtherVersion="1.1">
            ...
        </data>
    </Request>
</s:Body>

So far, we have used objects System.ServiceModel.Channels.Messagedirectly, which is a little painful. We are trying to move on to using strong types that look like this:

[MessageContract(IsWrapped = false)]
public class Request
{
    [MessageBodyMember]
    [XmlAttribute("version")]
    public string Version;

    [MessageBodyMember]
    [XmlElement("data")]
    public SomeOtherType Data;
}

[MessageContract(IsWrapped = false)]
public class Response
{
    [MessageBodyMember]
    [XmlAttribute("version")]
    public string Version;

    [MessageBodyMember]
    [XmlElement("data")]
    public SomeOtherType ResponseData;
}

[ServiceContract]
[XmlSerializerFormat]
public interface Service
{
    [OperationContract(Action = "request", ReplyAction = "response")]
    Response ServiceOperation(Request req);
}

Unfortunately, when we try to start, we get the error message: "Unhandled exception of type" System.InvalidOperationException "occurred in System.ServiceModel.dll

: XmlSerializer System.Xml.Serialization.XmlAttributeAttribute . XmlElement, XmlArray, XmlArrayItem XmlAnyElement MessageContract, IsWrapped . "

, "IsWrapped" true . XML ?

+4
1

XmlElement (typeof (data))

-3

All Articles