none
400 Bad Request connecting to WCF SOAP MTOM sample from embedded client RRS feed

  • Question

  • I created a simple WCF MTOM service based on the CodeProject sample here: <http://www.codeproject.com/Articles/632101/Mtom-Encoding-in-WCF>

    I am hosting it with IIS Express running on a Windows 10 machine. I am able to connect to it with a .NET client, and I have captured the HTTP request and response. Now I would like to use an embedded client to connect to this service.

    As a first step, I have attempted to use telnet from a client machineT

    The captured HTTP request multipart message looks like this:

    POST /Service1.svc HTTP/1.1
    MIME-Version: 1.0
    Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:34450500-f156-44c4-9029-39b25c2794d5+id=2";start-info="application/soap+xml"
    VsDebuggerCausalityData: uIDPo1KWW5y3uwVDgCIgEESskYMAAAAAMvkL+qgn/EOABoi12Ti65Uyk1HOupMNEqOqG7glAPv4ACQAA
    Host: 192.168.0.10:8080
    Content-Length: 865
    Expect: 100-continue
    Accept-Encoding: gzip, deflate
    
    --uuid:34450500-f156-44c4-9029-39b25c2794d5+id=2
    Content-ID: <http://tempuri.org/0>
    Content-Transfer-Encoding: 8bit
    Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml"
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/IService1/StoreData</a:Action><a:MessageID>urn:uuid:c6cb5104-adfd-4040-a2eb-a2cb659e8f2a</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://192.168.0.10:8080/Service1.svc</a:To></s:Header><s:Body><StoreData xmlns="http://tempuri.org/"><device>22222</device><time>2016-01-10T14:34:54.2151851-06:00</time><data>AwIB</data></StoreData></s:Body></s:Envelope>
    --uuid:34450500-f156-44c4-9029-39b25c2794d5+id=2--
    

    When I use Telnet to send this, I get a status 400 Bad request.

    If I simplify the request to a single message (not multipart), I get a correct response. The simple request looks like this:

    POST /Service1.svc HTTP/1.1
    Content-Type: application/soap+xml
    Host: 192.168.0.10:8080
    Content-Length: 611
    
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/IService1/StoreData</a:Action><a:MessageID>urn:uuid:c6cb5104-adfd-4040-a2eb-a2cb659e8f2a</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://192.168.0.10:8080/Service1.svc</a:To></s:Header><s:Body><StoreData xmlns="http://tempuri.org/"><device>22222</device><time>2016-01-10T14:34:54.2151851-06:00</time><data>AwIB</data></StoreData></s:Body></s:Envelope>
    

    (Sorry for the lack of line breaks.)

    I tried to extend the simple case minimally to get to a successful multipart request, but I continue to get status 400 Bad Request. Here is my latest attempt to generate a simple multipart request. I found a lot of good information here that gave guidelines for MTOM messages with WCF,

    POST /Service1.svc HTTP/1.1
    MIME-Version: 1.0
    Content-Type: multipart/related;type="application/xop+xml";start="<http://tempuri.org/0>";boundary="GATES";start-info="text/xml"
    Host: 192.168.0.10:8080
    Content-Length: 770
    
    --GATES
    Content-ID: <http://tempuri.org/0>
    Content-Transfer-Encoding: 8bit
    Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/IService1/StoreData</a:Action><a:MessageID>urn:uuid:c6cb5104-adfd-4040-a2eb-a2cb659e8f2a</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://192.168.0.10:8080/Service1.svc</a:To></s:Header><s:Body><StoreData xmlns="http://tempuri.org/"><device>22222</device><time>2016-01-10T14:34:54.2151851-06:00</time><data>AwIB</data></StoreData></s:Body></s:Envelope>
    --GATES--
    

    So, a few questions...

    1. Does anyone know what I am doing wrong here?
    2. How can I get more information from the server side about what is going wrong (what is causing the Bad Request).
    3. Is anyone aware of any public MTOM services that I can use to test my client?

    Thanks!

    Monday, January 25, 2016 3:58 AM

All replies

  • The 400 means that the Web server through the 400 and swallowed the true exception that was being thrown  by the program, which you'll to dig in and debug it somehow.

    Fiddler may help in debugging.

    Tuesday, January 26, 2016 12:51 AM
  • Hi Mat Kramer,

    According to this case, in my opinion, you can try set the trace configuration to WCF service.

    Then we can catch the more detailed error message. That will help us to find the root issue.

    For 400 bad request. I guess maybe that  the parameter is not matched. Or the data size is

    bigger than the set number in web.config file.

    Also, we can use the fiddler to debug the service as DA924 said.

    For more information, please refer to the following article:

    1.Configuring Tracing

    Configure the binding as below:

    <bindings>
      <basicHttpBinding>
        <binding name="FileTransferServicesBinding"
          transferMode="Streamed" messageEncoding="Mtom"
          sendTimeout="01:05:00" receiveTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
     maxArrayLength="2147483647" maxBytesPerRead="2147483647"
     maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    

    Hope it helps.

    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.

    Friday, January 29, 2016 6:29 AM
    Moderator