禁用WCF客户端证书和用户名凭据我无法让WCF客户端连接到需要客户端证书和用户名/密码的服务器。我已经使用以下方法使用JUST客户端证书进行了验证:varbinding=newWSHttpBinding(SecurityMode.Transport);binding.Security.Transport=newHttpTransportSecurity();binding.Security.Transport.ClientCredentialType=HttpClientCredentialType.Certificate;varea=newEndpointAddress(EndpointUrl);使用(varp=newServiceReference1.AAAClient(binding,ea)){System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName,CertificateSubject);varx=p.RequiresClientCertificateOnly();Console.WriteLine("状态:"+x.status);}catch(Exceptionex){Console.WriteLine(ex.ToString());}控制台.WriteLine();下一个合乎逻辑的步骤是添加用户名/密码部分,但它返回403Unauthorized。我知道凭据和证书是有效的,因为我在中间使用fiddler来提供客户端证书和用户名/密码并且它工作正常,只是在通过WCF使用或同时发送客户端证书和使用名称/密码的用户。尝试使用双方的代码如下(尝试使用WSHttpBinding和BasicHttpBinding–双方的结果相同):varbinding=newBasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);binding.Security.Transport.ClientCredentialType=HttpClientCredentialType.Certificate;binding.Security.Message.ClientCredentialType=BasicHttpMessageCredentialType.UserName;varea=newEndpointAddress(EndpointUrl);使用(varp=newServiceReference1.PingPortTypeClient(binding,ea)){System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName,CertificateSubject);p.ClientCredentials.UserName.UserName=用户名;p.ClientCredentials.UserName.Password=密码;varx=p.pingDatabase();Console.WriteLine("状态:"+x.status);}catch(Exceptionex){Console.WriteLine(ex.To细绳());}控制台.WriteLine();当我直接在浏览器中访问URL-我收到错误:HTTP错误403.7-禁止访问您尝试访问的页面要求您的浏览器具有Web服务器套接字层(SSL)客户端证书认可的安全性这表明在上面的第二个示例没有发送证书,因为它收到相同的错误(403)。有人可以帮我配置WCF以提供客户端证书和用户名/密码吗?我已经在网上搜索过,这里的“类似问题”根本没有帮助。现在变得非常沮丧-我错过了什么?如果您同时需要用户名(消息级别)和证书(传输级别),则必须使用自定义绑定。例如:messageVersion的值取决于你想使用WSHttp还是BasicHttp。目前我将它设置为“默认”,即WSHttp,对于Basic,设置为“Soap11”。以上就是C#学习教程:禁止WCF客户端证书和用户名凭据共享的全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
