我们在 IIS 中托管了一个 WCF 服务,客户端 dll 正在尝试访问该服务。该服务在 IIS 中绑定(bind)以使用 HTTPS 并设置为忽略客户端证书,这工作得很好,但需要 SSL 会导致问题。
我真的不明白的是,调用服务的一种方法工作得很好,但调用另一种方法不起作用,我收到以下错误:“HTTP 请求被禁止使用客户端身份验证方案‘匿名’ '.System.Net.WebException:远程服务器返回错误:(403)禁止访问。”
这可能是什么原因造成的?我是 WCF 的新手,所以如果我遗漏了什么或者是否需要更多信息,请告诉我。
这里是一些服务配置代码:
this.Description.Behaviors.Add(new FaultConversionErrorHandler());
this.Description.Behaviors.Add(new LoggingErrorHandler());
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
ServiceEndpoint endpoint = this.AddServiceEndpoint(typeof(ILicenseService), binding, String.Empty);
SecurityEndpointBehavior securityEndpointBehavior = new SecurityEndpointBehavior();
endpoint.Behaviors.Add(securityEndpointBehavior);
这是客户端引用服务的方式:
EndpointAddress a = new EndpointAddress(licenseServiceUrl);
Binding b = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
LicenseServiceClient client = new LicenseServiceClient(b, a);
client.Endpoint.Behaviors.Add(new SecurityEndpointBehavior());
最佳答案
您可以通过更改绑定(bind)信息来解决它。 将 TransportClientCredential Type 设置为证书以在 IIS SSL 设置中使用所需的证书。
如果是Ws-Http就有些不同了。 WCF WS 服务主机实际上正在检查传入的客户端请求证书是否存在于 Trusted People 中。 所以远程证书应该存在于服务器的受信任的人。
或者添加 CustomValidator 并覆盖行为。
关于wcf - 要求使用 WCF 的 SSL 会导致 "The HTTP request was forbidden with client authentication scheme ' 匿名“错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16240160/