I've been tasked with creating a SOAP service to receive messages that contain MTOM attachments, but unfortunately I don't control the format of the message being sent, so I need to reverse engineer a sample message to create the schema for the data I will receive.
It appears that CoreWCF is the recommended solution for .NET 6, and that this supports MTOM, however, I'm struggling to match the format of the XML that's being provided in the SOAP message, but I'm not locked into CoreWCF if there's a better way to handle this with another library.
The XML I'm receiving looks similar to the below:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xop="http://www.w3.org/2004/08/xop/include">
<soap:Body>
<ROOTDOC>
<INFO myAttribute="ABC123">
<ATTACHMENTS>
<ATTACHMENT><xop:Include href="cid:45487@domain.com"/></ATTACHMENT>
<ATTACHMENT><xop:Include href="cid:23578@domain.com"/></ATTACHMENT>
</ATTACHMENTS>
</INFO>
</ROOTDOC>
</soap:Body>
</soap:Envelope>
I've so far tried creating an XSD based on this XML, and using svcutil to try and create Data Contracts. This provided a very barebones class structure that gave me the 'INFO' element, but no property for the 'myAttribute' attribute, and nothing to navigate to any of the children of that without basically writing my own XML deserializer.
I've tried creating just the class structure, and tagging the classes with [DataContract]
attributes and the members with [DataMember]
attributes, however, this only seems to support 'myAttribute' as being a child element, rather than an attribute.
I've tried simply creating the class structure, and tagging the classes with various [XmlElement]
and [XmlAttribute]
attributes, but these just seem to be ignored.
Can anyone point me in the right direction?
I've now managed to match the format as closely as I believe is possible.
To do this I've had to create a custom MessageContract
which allows me to control the element and namespace used for the top-most level (ROOTDOC
in my case) and on the ServiceContract
I had to add the attribute XmlSerializerFormat
which allows WCF to use the XmlSerializer
, and that then allows me to control the child elements/attributes and their namespaces using standard XmlElement
and XmlAttribute
attributes.