Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error consuming webservice, content type "application/xop+xml" does not match expected type "text/xml"

I'm having a weird issue when consuming a webservice for a product that my company has bought. The product is called Campaign Commander and it's made by a company called Email Vision. We're trying to use the "Data Mass Update SOAP API".

Whenever I try to call any of the methods on the webservice, the call actually succeeds but the client fails when processing the response and I get an exception.

The details of the errors are below, thanks for any help you guys can offer.

Error using Web Reference (old style webservice client)

When consume the service as a Web Reference I get an InvalidOperationException for any call that I make, with the following message:

Client found response content type of 'multipart/related; type="application/xop+xml"; boundary="uuid:170e63fa-183c-4b18-9364-c62ca545a6e0"; start="<[email protected]>"; start-info="text/xml"', but expected 'text/xml'. The request failed with the error message: --  --uuid:170e63fa-183c-4b18-9364-c62ca545a6e0 Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"; Content-Transfer-Encoding: binary Content-ID: <[email protected]>  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   <soap:Body>     <ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/">       <return>DpKTe-9swUeOsxhHH9t-uLPeLyg-aa2xk3-aKe9oJ5S9Yymrnuf1FxYnzpaFojsQSkSCbJsZmrZ_d3v2-7Hj</return>     </ns2:openApiConnectionResponse>   </soap:Body> </soap:Envelope> --uuid:170e63fa-183c-4b18-9364-c62ca545a6e0-- --. 

As you can see, the response soap envelope looks valid (this is a valid response and the call succeeded), but the client seems to have a problem with the content type and generates an exception.

Error using Service Reference (WCF client)

When I consume the service as a Service Reference I get a ProtocolException for any call that I make, with the following message:

The content type multipart/related; type="application/xop+xml"; boundary="uuid:af66440a-012e-4444-8814-895c843de5ec"; start="<[email protected]>"; start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 648 bytes of the response were: ' --uuid:af66440a-012e-4444-8814-895c843de5ec Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"; Content-Transfer-Encoding: binary Content-ID: <[email protected]>  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   <soap:Body>     <ns2:openApiConnectionResponse xmlns:ns2="http://api.service.apibatchmember.emailvision.com/" xmlns:ns3="http://exceptions.service.apibatchmember.emailvision.com/">       <return>Dqaqb-MJ9V_eplZ8fPh4tdHUbxM-ZtuZsDG6GalAGZSfSzyxgtuuIxZc3aSsnhI4b0SCbJsZmrZ_d3v2-7G8</return>     </ns2:openApiConnectionResponse>   </soap:Body> </soap:Envelope> --uuid:af66440a-012e-4444-8814-895c843de5ec--'. 

Just like with the previous example; we've got a valid soap response and the call was successful, but the client seems to have a problem with the content type and has generated an exception.

Are there any options I can set so the client doesn't have a problem with the response type? I've done some Google searches, but nothing that I've found has helped me so far.

like image 311
Doctor Jones Avatar asked May 08 '12 09:05

Doctor Jones


2 Answers

For anyone suffering from the same problem; I've found a solution for consuming the web service as a Service Reference (WCF). The BasicHttpBinding.MessageEncoding property needs setting to "Mtom".

Here's a snippet of the required config setting:

<configuration>   <system.serviceModel>     <bindings>       <basicHttpBinding>         <binding messageEncoding="Mtom">                   </binding>       </basicHttpBinding>     </bindings>   </system.serviceModel> </configuration> 

Edit: If you are having the same issue with a custom binding please refer to the answer from @robmzd.

I still haven't found a solution for consuming it as an old style Web Reference yet.

like image 129
Doctor Jones Avatar answered Oct 08 '22 00:10

Doctor Jones


After having struggled with this for a few days, I found a remarkably simple solution for this problem:

  1. Activate the Configuration Editor by selecting Tools->WCF Service Configuration Editor from the main menu in VS2010;
  2. Close it again;
  3. Right-click on the App.Config file to find a new menu item "Edit WCF Configuration";
  4. Click on the binding;
  5. Change the MessageEncoding to Mtom;
  6. Save.

I hope this will help someone.

like image 26
Mark Smit Avatar answered Oct 08 '22 00:10

Mark Smit