Using the WCF Service Using BasicHttpBinding and Windows Authentication

I have a WCF service with the following binding:

<basicHttpBinding> <binding name="bind" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" /> <message algorithmSuite="Default" clientCredentialType="UserName"/> </security> </binding> </basicHttpBinding> 

I consume it dynamically in code with this endpoint:

 BasicHttpBinding binding = new BasicHttpBinding(); binding.Name = "bind"; binding.MaxBufferSize = int.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; ServiceEndpoint endPoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(ImyContract)), binding, new EndpointAddress(endPointAddress)); endPoint.Name = name; ChannelFactory<ImyContract> channelFactory = new ChannelFactory<ImyContract>(endPoint); 

When I look at the service, everything works exactly as expected, however when connecting through the application I get:

Content Type Text / xml; charset = utf-8 is not supported by the http: //localhost/SynchronizationService/SyncService.svc/DataBinding service . Customer and service relationships may not be compatible.

I understand that this error often occurs because basicHttpBinding using SOAP 1.1 and wsHttpBinding uses 1.2, however I do not use SSL on the server and have a different endpoint that uses streaming, so switching is not an option for me. What am I doing wrong, what prevents me from using the service correctly?

UPDATE:

In addition, I do not use basicHttpBinding by default on the client, but I set the security according to the expected server. I set security using this method:

 private static BasicHttpSecurity SetEndpointSecurity() { BasicHttpSecurity security = new BasicHttpSecurity(); HttpTransportSecurity transport = new HttpTransportSecurity(); BasicHttpMessageSecurity message = new BasicHttpMessageSecurity(); security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; transport.ClientCredentialType = HttpClientCredentialType.Windows; transport.ProxyCredentialType = HttpProxyCredentialType.None; transport.Realm = ""; message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default; security.Transport = transport; security.Message = message; return security; } 
+4
source share
1 answer

Thanks to the_ajp for your suggestion to let .NET build a proxy class and then re-implement its endpoint in the code, as this led me to the right solution!

As it turns out, my attempts to resolve the error "client and service bindings may not be compatible." This led me to make the client and server endpoint bindings similar. The key was to explicitly specify TextEncoding as UTF-8 on the client endpoint and use wsHttpBinding on the client, although I was connected to the baseHttpBinding on the server. This saved the message in SOAP 1.2 from source to destination without requiring SSL security on the server.

Thank you for your help in finding the right solution!

Kris C, I hope this will be useful to you in what you are working on next :)!

+1
source

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


All Articles