5

I have referenced WCF service in class library and that class library in a web application. When I tried to invoke a method from the service I am getting below exception.

"Content Type multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:901bc2e6-6d57-4363-9f99-41ca4884ce16+id=1";start-info="text/xml" was not supported by service https://URL_OF_Service/.  The client and service bindings may be mismatched."

Here is my configurations

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CoreSoapBinding">
          <textMessageEncoding messageVersion="Soap12" />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://URL_OF_Service/" binding="customBinding"
          bindingConfiguration="CoreSoapBinding" contract="ContractName"
          name="CoreSoapPort" />
    </client>
  </system.serviceModel>

And I created binding object in the application and passed to the service.

BasicHttpBinding binding = new BasicHttpBinding()
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            binding.Name = "CoreSoapPort";
            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.BypassProxyOnLocal = false;
            binding.UseDefaultWebProxy = true;
            binding.MessageEncoding = WSMessageEncoding.Mtom;
            binding.AllowCookies = false;
            binding.TransferMode = TransferMode.Buffered;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            Encoding textencoding = Encoding.UTF8;
            binding.TextEncoding = textencoding;
            binding.MaxReceivedMessageSize = Int32.MaxValue;

I tried changing the configuration to multiple to match the server configuration. But no luck.

Pradeep
  • 4,612
  • 10
  • 38
  • 50
  • The error message is saying mtom content type (multipart/related) isn't supported by the service. Why do you think you need to specify mtom in your binding configured by code? – MattC Oct 08 '15 at 19:17
  • I think it is for you [WCF Error: the client and service bindings may be mismatched](http://stackoverflow.com/questions/2887776/wcf-error-the-client-and-service-bindings-may-be-mismatched) Hope it helps. – Lewis Hai Oct 09 '15 at 07:54
  • http://stackoverflow.com/questions/2887776/wcf-error-the-client-and-service-bindings-may-be-mismatched Hope it helps – Lewis Hai Oct 09 '15 at 07:55

2 Answers2

0

Have you tried to change your message encoding configuration to MTOM? IMHO, I think you should not used both configuration file and programmatically to configure your WCF service because it will give you a lot of headache. I suggest to stick to one, it's either configuration file or programmatically.

Community
  • 1
  • 1
jtabuloc
  • 2,479
  • 2
  • 17
  • 33
0

The error happens because of binding mismatch. You server binding is a BasicHttpBinding, and your client is a CustomBinding.

As your service are using BasicHttpBinding, try to configure your client with same binding, but, if you want to use Soap12, you will need to configure your server side as CustomBinding, something like this:

CustomBinding binding = new CustomBinding();
            SymmetricSecurityBindingElement ssbe =
                SecurityBindingElement.CreateSspiNegotiationBindingElement(true);
            // Add the SymmetricSecurityBindingElement to the BindingElementCollection.
            binding.Elements.Add(ssbe);
            binding.Elements.Add(new TextMessageEncodingBindingElement());
            binding.Elements.Add(new HttpTransportBindingElement());

You can read more here: https://msdn.microsoft.com/en-us/library/ms730305%28v=vs.110%29.aspx

Hope it helps.

Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43