Can't get Mtom response in wcf RRS feed

  • Question

  • I'm trying to build a servic with WCF which returnes back pdf files as attachments to mtom message. I'm creating service contract by WSDL file and when I test the result in SOAPUI I always receive inline response ( the content of pdf file is in the body of mesage as binary data. Also when I wanted to set my output header to be type of Multipart/related I received error that the content-type should be text/xml.

    The raw view that I have in my out put is :

    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Length: 1879
    Content-Type: text/xml; charset=utf-8
    Server: Microsoft-IIS/7.5
    Set-Cookie: ASP.NET_SessionId=ddw0fvgxfd14hbxcixjd2ngf; path=/; HttpOnly
    Accept: multipart/form-data
    ContentType: multipart/related; type="application/xop+xml";start="<>";boundary="uuid:77ab9e75-4e22-46f0-bbed-4f14cf65e9a8";start-info="application/soap+xml"
    MIME-Version: 1.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Thu, 21 Jan 2016 14:18:53 GMT

    <s:Envelope xmlns:s=""><s:Body><GetMaintenanceProtocolPdfAttachmentResponse xmlns=".......">

    <GetMaintenanceProtocolPdfAttachmentResult xmlns:a="" xmlns:i="">





    The wsdl file is:

    <xs:complexType name="pdfAttach">
          <xs:element name="Titles" type="xs:string" nillable="true" minOccurs="0" maxOccurs="1"/>
          <xs:element name="file" type="xs:base64Binary" xmime:expectedContentTypes="application/octet-stream" minOccurs="0" maxOccurs="1" />
    <xs:element name="GetMaintenanceProtocolPdfAttachmentResponse" >
            <xs:element name="GetMaintenanceProtocolPdfAttachmentResult" type="tech:pdfAttach" minOccurs="0" maxOccurs="1"  />
    <operation name="GetMaintenanceProtocolPdfAttachment">
          <input message="tns:GetMaintenanceProtocolPdfAttachmentRequest"/>
          <output message="tns:GetMaintenanceProtocolPdfAttachmentResponse"/>
     <operation name="GetMaintenanceProtocolPdfAttachment">
          <soap:operation soapAction="http://.../contract/technicalinformation/v1/GetMaintenanceProtocolPdfAttachment" style="document"/>
            <soap:body use="literal"/>
            <soap:body use="literal"/>

    Also the service implementation is:

    public static xmlns....technicalinformation.v1.pdfAttach TranslatePdfAttachment(PDFAttachment Attachment)
                pdfAttach tisPdfAttach =
                    new pdfAttach();
                tisPdfAttach.Titles =;
                tisPdfAttach.file = Attachment.content;
                MemoryStream MTOMInMemory = new MemoryStream();
                XmlDictionaryWriter TW = XmlDictionaryWriter.CreateMtomWriter(MTOMInMemory, Encoding.UTF8, Int32.MaxValue, "");
                DataContractSerializer DCS = new DataContractSerializer(tisPdfAttach.GetType());
                DCS.WriteObject(TW, tisPdfAttach);
                           WebOperationContext.Current.OutgoingResponse.Headers["Accept"] = "multipart/form-data";
               string boundary = "uuid:" + Guid.NewGuid().ToString();
               string startUri = "";
               string startInfo = "application/soap+xml";
               string contentType = "multipart/related; type=\"application/xop+xml\";start=\"<" + startUri +  ">\";boundary=\"" + boundary +  "\";start-info=\"" + startInfo + "\"";
               WebOperationContext.Current.OutgoingResponse.Headers["MIME-Version"] = "1.0";
                return tisPdfAttach;

    Can some one help me to solve this problem.

    Thank you

    • Edited by hastikeyvan Thursday, January 21, 2016 3:17 PM to make it more clear
    Thursday, January 21, 2016 2:50 PM


  • Hi hastikeyvan,

    For>> Also when I wanted to set my output header to be type of Multipart/related I received error that the content-type should be text/xml.

    Could you share the detailed error message and your web.config file?

    Did you set the messageEncoding on your service within the binding? like this:

            <binding name="b1" messageEncoding="Mtom">
              <security mode="None" />
              <reliableSession enabled="false" />

    Best Regards,

    Wanjun Dong 

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Monday, January 25, 2016 5:18 AM