Error calling WCF web service

I referenced the WCF service in the class library and this class library in the web application. When I tried to call a method from a service, I get below the 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 are 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 a binding object in the application and passed it 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 by a few to match the server configuration. But no luck.

+5
source share
2 answers

Have you tried changing the encoding of messages to MTOM ? IMHO, I think you should not use both configuration files and programmatically to set up your WCF service, because it will give you a lot of headache. I suggest sticking with one thing, it's either a configuration file, or programmatically.

0
source

The error occurs due to a mismatch in the binding. You are bound to the BasicHttpBinding server, and your client is CustomBinding .

As your service uses BasicHttpBinding , try setting up the client with the same binding, but if you want to use Soap12, you will need to configure the 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 this helps.

0
source

Source: https://habr.com/ru/post/1232676/


All Articles