4
votes

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 am consuming 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 browse to the service everything works exactly as expected, however when connecting through the application I get:

Content Type text/xml; charset=utf-8 was not supported by service http://localhost/SynchronizationService/SyncService.svc/DataBinding. The client and service bindings may be mismatched.

I understand this error is caused often because basicHttpBinding using SOAP 1.1 and wsHttpBinding uses 1.2, however, I am not using SSL on the server, and have another endpoint using streaming, so switching is not an option for me. What am I doing wrong that is prevening me from consuming the service correctly?

UPDATE:

Also, I am not using the default basicHttpBinding on the client, but setting security to match what the server is expecting. I am setting the security with 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;
}
1
try creating a proxy with svcutil and look how its done in there. Oh and are you also using a metadata exchange endpoint. because that does often cause this problem as well, if you accidentally use that uri.albertjan
Removed my answer as I don't think it's correct having looked at BasicHTTPBinding some more (helpful to know for something I'm going to try next). The following link (and the comments) seems like a useful place to start: rickgaribay.net/archive/2007/04/04/…Kris C
Is the server version definitely using the binding specified above? With .NET4, I found that until I got my namespaces and suchlike correct, the default binding that it provides (wsHTTPBinding) was still in effect and my configuration was not active. Using svcutil as described in @the_ajp's comment may help to check.Kris C

1 Answers

1
votes

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

As it turns out, my attempts to resolve the error "The client and service bindings may be mismatched.", led me to make the client and server endpoint bindings TOO similar. The key was to explicitly specify the TextEncoding as UTF-8 on the client endpoint and to utilize wsHttpBinding on the client, even though I was connecting to a basicHttpBinding on the server. This kept the message in SOAP 1.2 all the way from origin to destination, without requiring setting up SSL security on the server.

Thanks for all your help getting to the right solution guys!

Kris C, hopefully this can be of use to you in what you are working on next :)!