我有一个WCF服务,它为不同的WCF服务提供身份验证/授权。
以下是一个示例方法:
public int AddCustomerStopInfo(CustomerStop stop)
{
var request = new AddCustomerStopInfoRequest(stop);
var service = new ChannelFactory<IAccountManagementChannel>("WSHttpBinding_IAccountManagement").CreateChannel();
try
{
var response = service.AddCustomerStopInfo(request);
service.Close();
return response.AddCustomerStopInfoResult;
}
catch (CommunicationException e)
{
service.Abort();
throw;
}
}
在service.AddCustomerStopInfo()方法调用上,抛出异常。消息显示:
安全通道无法打开,因为与安全协商 远程端点失败。这可能是由于缺席或不正确 用于创建的EndpointAddress中指定的EndpointIdentity 渠道。请验证指定或暗示的EndpointIdentity EndpointAddress正确识别远程端点。
服务的服务器绑定如下所示:
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IAccountManagement" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="100065536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None" />
</binding>
...
<services>
<service behaviorConfiguration="ABCD.Service.Service1Behavior"
name="ABCD.Service.AccountManagement">
<endpoint address="" behaviorConfiguration="ValidationBehavior"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAccountManagement"
name="WSHttpBinding_IAccountManagement" contract="ABCD.Service.IAccountManagement">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" behaviorConfiguration="" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
客户方:
<client>
<endpoint address="[site location]/AccountManagement.svc"
binding="wsHttpBinding"
contract="IAccountManagement" name="WSHttpBinding_IAccountManagement">
</endpoint>
</client>
两种服务都在同一台服务器上。如果其他服务有<security mode="None">
,我不明白为什么会收到此错误?
答案 0 :(得分:1)
当您尝试通过wsHttpBinding
使用安全绑定时,您需要通过https连接到服务器并使用调试代码来允许与测试服务器的许可连接。
这是因为您只有自签名证书,而且https在安全证书方面非常严格。