【发布时间】:2011-11-18 14:57:09
【问题描述】:
我有一个具有以下绑定的 WCF 服务:
<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);
当我浏览到该服务时,一切都按预期工作,但是当我通过应用程序连接时:
内容类型文本/xml; charset=utf-8 不受服务支持 http://localhost/SynchronizationService/SyncService.svc/DataBinding。 客户端和服务绑定可能不匹配。
我知道这个错误通常是因为 basicHttpBinding 使用 SOAP 1.1 而 wsHttpBinding 使用 1.2,但是,我没有在服务器上使用 SSL,并且有另一个使用流的端点,所以切换不是我的选择。我做错了什么导致我无法正确使用服务?
更新:
另外,我没有在客户端使用默认的 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,这通常也会导致此问题。
-
删除了我的答案,因为我认为更多地查看 BasicHTTPBinding 是不正确的(有助于了解我接下来要尝试的事情)。以下链接(和 cmets)似乎是一个有用的起点:rickgaribay.net/archive/2007/04/04/…
-
服务器版本确定使用上面指定的绑定吗?使用 .NET4,我发现在我的命名空间等正确之前,它提供的默认绑定 (wsHTTPBinding) 仍然有效并且我的配置未激活。使用@the_ajp 评论中描述的 svcutil 可能有助于检查。