Search code examples
wcfsoap.net-6.0mtomcorewcf

CoreWCF Service Receiving MTOM File Attachment


I'm attempting to create a SOAP service using .NET 6 and CoreWCF that uses a format dictated by one of our suppliers to receive a SOAP message with a bunch of metadata, and a set of file attachments sent using MTOM.

When I specify the property of one of the classes I'm using for my request is a byte array, I can receive the file when it's specified in the following format:

<parent>
  <child>
    <attachment>cid:mycontentid</attachment>
  </child>
</parent>

But the supplier is sending the file using an Include element that's specified in the http://www.w3.org/2004/08/xop/include schema, that they're referencing by namespace.

<parent xmlns:xop="http://www.w3.org/2004/08/xop/include">
  <child>
    <attachment>
      <xop:Include href="cid:mycontentid"/>
    </attachment>
  </child>
</parent>

When I try to send a file using that same format, whatever I try, I just get a null value.

My attachment/include classes currently look like this:

public class Attachment
{
  //WSDL looks right, but deserializes to null
  //[XmlElement(ElementName = "Include", Namespace="http://www.w3.org/2004/08/xop/include")]
  //public Include Include { get; set; }
  
  //WSDL looks right, but deserializes to null
  //[XmlElement(ElementName = "Include", Namespace="http://www.w3.org/2004/08/xop/include")]
  //public byte[] Include { get; set; }

  //WSDL looks wrong, only accepts <attachment>cid:...</attachment>
  public byte[] Include { get; set; }
}

public class Include 
{
  [XmlAttribute(AttributeName="href", Namespace="http://www.w3.org/2004/08/xop/include")]
  public byte[] Href { get;set; }
}

I'm not finding much by way of documentation that explains this stuff, and I'm struggling. Does anyone have any idea how I'd implement this with CoreWCF (or even with original WCF and I can try to adapt from there)?


Solution

  • The resolution to this one was simpler than it looked. Although my client was giving me a default for sending the MTOM attachment, I was still able to send MTOM attachments using an xop:Include element.

    My final implementation involved essentially removing the class called Attachment completely, and adding a property of Attachment to the class that's being serialized as the element 'child' that was of type byte[]. Once I did that, although SOAPUI was setting the default request XML to have cid:contentid as the child of the attachment element, CoreWCF did understand it correctly when I replaced that cid:contentid with an instance of <xop:Include href="cid:contentid"/> instead.