简体   繁体   English

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

[英]How to fix "The HTTP request was forbidden with client authentication scheme 'Anonymous'"

I'm having some issues implementing a client that talks to a WCF service.我在实现与 WCF 服务对话的客户端时遇到了一些问题。 It's a WCF hosted by another company so I don't have access to its code.它是由另一家公司托管的 WCF,因此我无权访问其代码。 I used the Connected Service provider tool in Visual Studio to generate the client code so that I could make requests and everything works fine on my local machine.我使用 Visual Studio 中的 Connected Service provider 工具来生成客户端代码,以便我可以发出请求,并且在我的本地机器上一切正常。 I am having an issue on our development environment where I receive the following error if I try to make a request with the client:我在我们的开发环境中遇到了一个问题,如果我尝试向客户端发出请求,我会收到以下错误:

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

I've been looking at the client code (it's a lot of code) which is generated by the Provider tool and I think it may have something to do with the following block of code.我一直在查看由 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;

This more linked to firewall rules within corporate network.这更多地与企业网络内的防火墙规则有关。

I had same issue using non authorized proxy but got resolved secured proxy with ntlm ClientCredentialType我使用非授权代理遇到了同样的问题,但使用 ntlm ClientCredentialType解决了安全代理

result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport; result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;

Security is provided using HTTPS.使用 HTTPS 提供安全性。 The service must be configured with SSL certificates.该服务必须配置 SSL 证书。 The SOAP message is protected as a whole using HTTPS. SOAP 消息使用 HTTPS 作为一个整体受到保护。 The service is authenticated by the client using the service's SSL certificate.客户端使用服务的 SSL 证书对服务进行身份验证。 The client authentication is controlled through the ClientCredentialType.客户端身份验证通过 ClientCredentialType 进行控制。

https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpsecuritymode?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.basichttpsecuritymode?view=netframework-4.8

This error typically indicates that the WCF server authenticates the client-side with a certificate.此错误通常表示 WCF 服务器使用证书对客户端进行身份验证。 The error will occur when the trust relationship between the server and the client have not been established yet.当服务器和客户端之间的信任关系尚未建立时,就会发生该错误。
在此处输入图片说明
In general, we need to provide client credential to be authenticated by the server so that be able to call the service.通常,我们需要提供客户端凭据以供服务器进行身份验证,以便能够调用服务。 As for what kind of credentials need to be provided, it depends on the binding information on the server-side.至于需要提供什么样的凭证,取决于服务端的绑定信息。

 BasicHttpBinding binding = new BasicHttpBinding();
            binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

Namely, the above errors have indicated that the server authenticates the client with a certificate.即,上述错误表明服务器使用证书对客户端进行身份验证。

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

About authenticating the client with a certificate, you could refer to the below link for details.关于使用证书对客户端进行身份验证,您可以参考以下链接了解详细信息。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
Feel free to let me know if there is anything I can help with.如果有什么我可以帮忙的,请随时告诉我。

Thanks for all the suggestions.感谢所有的建议。 This was actually just caused by a firewall rule that was setup within our organisation.这实际上只是由我们组织内设置的防火墙规则引起的。 Once that was removed the code worked as expected.删除后,代码按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 客户端身份验证方案“匿名”禁止HTTP请求。 3 - The HTTP request was forbidden with client authentication scheme 'Anonymous'. 3 如何添加ClientCeritifcates,HTTP请求被禁止使用客户端身份验证方案'Anonymous' - How to add ClientCeritifcates, The HTTP request was forbidden with client authentication scheme 'Anonymous' 重现问题:客户端身份验证方案“匿名”禁止使用http请求 - Reproduce Issue: The http request was forbidden with client authentication scheme 'anonymous' 出现403禁止错误。 客户端身份验证方案“匿名”禁止HTTP请求 - Getting 403 Forbidden error. The HTTP request was forbidden with client authentication scheme 'Anonymous' 客户端身份验证方案“匿名”禁止 HTTP 请求。 远程服务器返回错误:(403) Forbidden - The HTTP request was forbidden with client authentication scheme 'Anonymous'. The remote server returned an error: (403) Forbidden 使用客户端身份验证方案“匿名”对HTTP请求进行未经授权的授权? - The HTTP request is unauthorized with client authentication scheme 'Anonymous'? HTTP 请求未使用“匿名”客户端身份验证方案授权 - The HTTP request is not authorized with the 'Anonymous' client authentication scheme 添加WCF服务引用时,HTTP请求被禁止,客户端身份验证方案“匿名”错误 - The HTTP request was forbidden with client authentication scheme 'Anonymous' error, when adding WCF service reference IIS托管具有SSL安全性的WCF-“ HTTP请求被客户端身份验证方案'Anonymous'禁止”错误 - IIS hosted WCF with SSL security -“The HTTP request was forbidden with client authentication scheme 'Anonymous'” error BizTalk 发送端口抛出错误 System.Net.WebException:HTTP 请求被禁止使用客户端身份验证方案“匿名” - BizTalk send port throws error System.Net.WebException: The HTTP request was forbidden with client authentication scheme 'Anonymous'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM