如何在 C# 中通过 HTTPS 使用 SOAP 服务?
Web 服务管理员给了我 WSDL、两个证书和一个私钥:
service.wsdl
ssl.cer
auth_cert.pem
auth_private_key.pem
在 Visual Studio 2010 中,我从 WSDL 添加了一个 Web 引用(服务引用不起作用)。 然后我尝试使用它,因为它是一个 http肥皂客户端:
MySoapClient client = new MySoapClient();
client.Operation();
并且我获得了这个堆栈跟踪:
Unhandled Exception: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
我与证书和私钥有什么关系?
我在网上找不到任何涉及此问题的教程或书籍。有什么提示吗?
更新
使用 Firefox 访问端点:
SSL 对等方无法验证您的 证书。 (错误代码: ssl_error_bad_cert_alert)
Webservice administrator gave me WSDL, two certificates and a private key:
service.wsdl
ssl.cer
auth_cert.pem
auth_private_key.pem
In Visual Studio 2010 I added a Web Reference (Service Reference didn't work) from the WSDL.
Then I tried to use it as it was an http soap client:
MySoapClient client = new MySoapClient();
client.Operation();
and I obtain this stack trace:
Unhandled Exception: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
What I have to do with certificates and private key?
I can't find any tutorial online nor books that covers this matter. Any hint?
Update
Accessing the endpoint with Firefox:
SSL peer cannot verify your
certificate. (Error code:
ssl_error_bad_cert_alert)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您仅使用服务,则不需要私钥。我猜你想要使用 https 进行双向身份验证。如果是这种情况,其工作原理如下:
在服务器上,管理员应使用私钥安装证书以启用 SSL(该密钥在 SSL 握手期间使用)。您的客户端使用它的公钥来检查证书是否有效并验证服务,因此在客户端您需要以某种方式检查它。如果两台机器都在 Windows 域中,这很容易(可以将其配置为使用域证书颁发机构)。如果没有,您需要将用于签署原始服务器证书的所有证书安装在客户端计算机上(在受信任的根 CA 存储中)。
第二部分是客户端对服务器的身份验证。您将客户端证书(它包含公钥)安装到个人存储并配置 WCF 代理以使用它:
将端点配置为使用此行为。一些注意事项:
这是一个非常复杂的主题,总是需要大量有时间进行研究。
查看这篇文章 http://blogs.msdn.com/b/imayak/archive/2008/09/12/wcf-2-way-ssl-security-using-certificates.aspx
希望这有帮助。
If you only consume the service the private key is not required. I can guess you want 2-way authentication with https. If this is the case here is how it works:
On the server the admin should install the cert with a private key to enable SSL (the key is used during SSL handshake). Its public key is used by your client to check if the cert is valid and to authenticate the service, so on the client side you somehow need to check it. If both machines are in Windows domain this is easy (it can be configured to use domain Certification Authority). If not, you need all the certs that were used to sign the original server cert to be installed on the client machine (in Trusted Root CA storage).
The second part is client authentication to the server. You install the client cert (it contains public key) to Personal storage and configure WCF proxy to use it:
Configure you endpoint to use this behavior. A few notes:
This is very complex topic and always require lot of time to research.
Check this article http://blogs.msdn.com/b/imayak/archive/2008/09/12/wcf-2-way-ssl-security-using-certificates.aspx
Hope this help.
管理员似乎已向您提供了用于在服务器上设置 SSL 的文件。您应该能够通过 WSDL.exe 运行 service.wsdl 来生成 C# 代理,这就是 VS 在添加 Web 引用时所做的事情。但我认为这不是你的问题。您看到网络级问题,因为异常是 System.Net.WebException。
其他文件看起来像是管理员用来将 SSL 添加到服务器的文件。通过共享私钥,如果任何启用 SSL 的服务使用此密钥,他可能会损害安全性。您应该在 WSDL 中查找任何服务端点,并尝试通过 SSL (https://) 在浏览器中访问这些端点。如果不能,则存在服务器配置问题。更正服务器上的 SSL 配置,您的 WSDL 应该可以工作,或者至少您会遇到新问题。
The admin seems to have given you the files used to setup SSL on the server. You should be be able to run service.wsdl through WSDL.exe to generate a C# proxy, which is what VS does when you add a Web Reference. I don't think this is your problem though. You are seeing a network level issue since the exception is a System.Net.WebException.
The other files look like they are what the admin was using to add SSL to the server. By sharing the private key he may have compromised the security if any SSL-enabled services using this key. You should look for any service end points in the WSDL and try to access those in your browser over SSL (https://). If you cannot then there is a server configuration issue. Correct the SSL configuration on the server and your WSDL should work, or at least you''ll have a new issue.