none
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="<http://tempuri.org/0>";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="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetMaintenanceProtocolPdfAttachmentResponse xmlns=".......">

    <GetMaintenanceProtocolPdfAttachmentResult xmlns:a="" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

    <a:Titles>MAI_PRINT_151852575_1.pdf</a:Titles>

    <a:file>PGLFeo61zK/..../==</a:file>

    </GetMaintenanceProtocolPdfAttachmentResult>

    </GetMaintenanceProtocolPdfAttachmentResponse></s:Body></s:Envelope>

    The wsdl file is:

    <xs:complexType name="pdfAttach">
        <xs:sequence>
          <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:sequence>
      </xs:complexType>
    
    <xs:element name="GetMaintenanceProtocolPdfAttachmentResponse" >
        <xs:complexType>
          <xs:sequence>
            <xs:element name="GetMaintenanceProtocolPdfAttachmentResult" type="tech:pdfAttach" minOccurs="0" maxOccurs="1"  />
                 </xs:sequence>
        </xs:complexType>
      </xs:element>
    <operation name="GetMaintenanceProtocolPdfAttachment">
          <input message="tns:GetMaintenanceProtocolPdfAttachmentRequest"/>
          <output message="tns:GetMaintenanceProtocolPdfAttachmentResponse"/>
          </operation>
    
    
     <operation name="GetMaintenanceProtocolPdfAttachment">
          <soap:operation soapAction="http://.../contract/technicalinformation/v1/GetMaintenanceProtocolPdfAttachment" style="document"/>
          <input>
            <soap:body use="literal"/>
          </input>
          <output>
            <soap:body use="literal"/>
          </output>
       
              </operation>

    Also the service implementation is:

    public static xmlns....technicalinformation.v1.pdfAttach TranslatePdfAttachment(PDFAttachment Attachment)
            {
                pdfAttach tisPdfAttach =
                    new pdfAttach();
    
                tisPdfAttach.Titles = Attachment.name;
                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);
                TW.Flush();
                Console.WriteLine(Encoding.UTF8.GetString(MTOMInMemory.ToArray()));
                           WebOperationContext.Current.OutgoingResponse.Headers["Accept"] = "multipart/form-data";
               string boundary = "uuid:" + Guid.NewGuid().ToString();
               string startUri = "http://tempuri.org/0";
               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";
                WebOperationContext.Current.OutgoingResponse.Headers["ContentType"]=contentType;
                    
            
               
               
                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

Answers

  • 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:

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

    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
    Moderator