wcf - 要求使用 WCF 的 SSL 会导致 "The HTTP request was forbidden with client authentication scheme ' 匿名“错误?

标签 wcf ssl client wcf-client anonymous

我们在 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/

相关文章:

c# - 关闭使用 WCF 的线程时的额外步骤?

c# - 如何从实现 IServiceBehavior/IOperationBehavior 的属性中获取 OperationContext

google-chrome - Chrome 中的 ERR_SSL_KEY_USAGE_INCOMPATIBLE

C# TLS 和 SQL Server

python - 如何从字符串中提取整数

.net - 如何强制 WCF 使用 xs :All instead of xs:Sequence so that SOAP element ordering is irrelevant?

c# - 在 IIS 上尝试我的 WCF 数据服务时得到 "401 - Unauthorized"

wordpress - 为什么我在 wordpress 页面上的 firefox 中连接不安全

java - Servicestack 或 SignalR 的 SSE Java 客户端

javascript - 用 Backbone 处理权限