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

Solution 1:

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.

Solution 2:

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.

Solution 3:

I had the same issue but with <customBinding>. To fix it you can configure Mtom Message Encoding using a separate <mtomMessageEncoding> configuration node under the binding.

<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="MyServiceBinding">
          <mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          </mtomMessageEncoding>
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>

Solution 4:

If you're self-hosting a WCF service and you're consuming the service with a WCF client. You must remember to set the MessageEncoding property in the host like this:

BasicHttpBinding binding = new BasicHttpBinding();
binding.MessageEncoding = WSMessageEncoding.Mtom;

I ran into this problem as well. My client kept throwing this Exception on start up and I couldn't figure out why until I realized that I forgot to set my bindings MessageEncoding property in the host application.