我有下面的结合WCF服务:消费WCF服务与basicHttpBinding的和Windows身份验证
<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>
我与这个端点动态地消费它在代码:
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);
当我浏览该服务的一切正如预期的那样,但是当通过应用程序连接时,我得到:
内容键入text/xml; charset = utf-8不支持服务 http://localhost/SynchronizationService/SyncService.svc/DataBinding。 客户端和服务绑定可能不匹配。
我理解,因为basicHttpBinding的使用SOAP 1.1这个错误往往是造成和的wsHttpBinding使用1.2,但是,我没有在服务器上使用SSL,并有使用流另一个端点,所以开关是不是我的选择。我做错了什么是阻止我正确使用服务?
UPDATE:
另外,我不使用客户端上的默认basicHttpBinding的,但设置安全性以匹配服务器期待。我用这个方法设置安全:
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;
}
尝试用svcutil创建一个代理并查看它在那里的完成情况。哦,你还在使用元数据交换端点吗?因为如果你不小心使用了那个uri,那也经常会导致这个问题。 – albertjan
删除我的答案,因为我不认为这是正确的看到BasicHTTPBinding更多(有助于知道我将要尝试的东西)。以下链接(和注释)似乎是一个有用的开始位置:http://rickgaribay.net/archive/2007/04/04/recipe-wcf-basichttpbinding-with-windows-authentication.aspx –
服务器版本绝对使用上面指定的绑定?在.NET4中,我发现直到我得到我的命名空间和类似这样的正确,它提供的默认绑定(wsHTTPBinding)仍然有效,并且我的配置没有激活。如@ the_ajp的评论中所述使用svcutil可能有助于检查。 –