首页 > 解决方案 > 如何修复“客户端身份验证方案‘匿名’禁止 HTTP 请求”

问题描述

我在实现与 WCF 服务对话的客户端时遇到了一些问题。这是由另一家公司托管的 WCF,因此我无权访问其代码。我使用 Visual Studio 中的 Connected Service 提供程序工具来生成客户端代码,以便我可以发出请求,并且在我的本地计算机上一切正常。我在我们的开发环境中遇到问题,如果我尝试向客户端发出请求,我会收到以下错误:

The HTTP request was forbidden with client authentication scheme 'Anonymous'

我一直在查看 Provider 工具生成的客户端代码(代码很多),我认为它可能与以下代码块有关。

System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
return result;

标签: c#.netwcfasp.net-core

解决方案


这更多地与企业网络内的防火墙规则相关联。

我在使用非授权代理时遇到了同样的问题,但使用 ntlm 解决了安全代理问题ClientCredentialType


推荐阅读