wcf – 具有证书身份验证的BasicHttpBinding – 错误“禁止”?
发布时间:2020-12-14 22:29:21 所属栏目:资源 来源:网络整理
导读:我正在尝试让WCF服务器和客户端使用BasicHttpBinding在传输级别上使用SSL证书相互进行身份验证.以下是创建服务器的方式: var soapBinding = new BasicHttpBinding() { Namespace = "http://test.com" };soapBinding.Security.Mode = BasicHttpSecurityMode.
我正在尝试让WCF服务器和客户端使用BasicHttpBinding在传输级别上使用SSL证书相互进行身份验证.以下是创建服务器的方式:
var soapBinding = new BasicHttpBinding() { Namespace = "http://test.com" }; soapBinding.Security.Mode = BasicHttpSecurityMode.Transport; soapBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; var sh = new ServiceHost(typeof(Service1),uri); sh.AddServiceEndpoint(typeof(IService1),soapBinding,""); sh.Credentials.ServiceCertificate.SetCertificate( StoreLocation.LocalMachine,StoreName.My,X509FindType.FindBySubjectName,"localhost"); sh.Open(); 这是客户: var binding = new BasicHttpBinding(); binding.Security.Mode = BasicHttpSecurityMode.Transport; var service = new ServiceReference2.Service1Client(binding,new EndpointAddress("https://localhost:801/Service1")); service.ClientCredentials.ClientCertificate.SetCertificate( StoreLocation.LocalMachine,"localhost"); service.ClientCredentials.ServiceCertificate.Authentication. CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust; service.HelloWorld(); localhost的证书位于Personal,Trusted Root和Trusted 3rd Party容器中. Internet Explorer可以连接到主机并查看WSDL.此外,SSL调用与ClientCredentialType = HttpClientCredentialType.None一起正常工作 HelloWorld()失败: System.ServiceModel.Security.MessageSecurityException occurred<br/> Message="The HTTP request was forbidden with client authentication scheme 'Anonymous'." 这是一个重新抛出的异常:“远程服务器返回错误:(403)Forbidden.” 如何解决wtf正在进行? 解决方法
在设置Security.Mode之后尝试在客户端中添加此项:
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- JavaScript:如何更改创建的span的CSS样式?
- selenium-webdriver – Canopy – 使用选择列表
- svg – 删除由角度组件创建的主机HTML元素选择器
- html – 您目前优化网页设计的最低屏幕分辨率是多
- 微信小程序swiper高度自适应
- Grails – 简单有很多问题 – 在create.gsp中使用
- 在Sublime Text 2中为HTML标记添加id =“”和cla
- html 空链接 href="#"与href="javascrip
- sublimetext2 – Sublime text word_separator C
- web-services – 如何通过预检请求从javascript调
热点阅读