c# - 使用证书的相互 SSL 的 WCF 身份验证错误

标签 c# web-services wcf ssl ssl-certificate

我正在尝试使用另一家公司发布的服务。关于认证和通信的规范是:

  • 肥皂
  • 带有双向 SSL 身份验证的 HTTPS(双向 SSL)
    • 使用他们发送给我们的公共(public)证书(我用作 ServiceCertificate)
    • 使用他们为我们创建的私有(private)证书(我用作 ClientCertificate)
  • WS-Security with UsernameToken

这是我到目前为止使用的代码:

WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
binding.SendTimeout = binding.CloseTimeout = binding.ReceiveTimeout = binding.OpenTimeout = new TimeSpan(0, 15, 0); // 15 minutes

Uri uri = new Uri(input.ServiceAddress);
EndpointAddress endpointAddress = new EndpointAddress(uri);

// Client creation
using (Client client = new Client(binding, endpointAddress))
{
    client.ClientCredentials.ClientCertificate.Certificate = input.PrivateCertificate;
    client.ClientCredentials.ServiceCertificate.DefaultCertificate = input.PublicCertificate;

    client.Open();

    // Service call
    ResponseType response = client.ServiceCall(params);
}

调用服务时出现此错误:

An error occurred while making the HTTP request to service. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.

我已经尝试过的事情:

  • 添加这行代码:“System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3;”
    • this 上找到的解决方案和 this
  • 在 netsh 端口注册公共(public)证书
    • 使用此命令:“netsh http add sslcert ipport=0.0.0.0:443 certhash=证书指纹 appid={应用程序 GUID}”
    • 基于我们在另一个项目中遇到的另一个问题

我不知道如何解决这个问题,而且我对此一无所知!已经搜索了很多,但我尝试的一切都不行!

最佳答案

碰巧我们的基础设施有一些网络问题。一旦我们从我的机器上移除了安全层,服务就会运行。

我猜证书(也许是 key )没有通过网络,我收到了那个错误(因为它没有进行身份验证)。

关于c# - 使用证书的相互 SSL 的 WCF 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26588463/

相关文章:

c# - 如何防止用户浏览 Web 浏览器控件中的某些网站?

c# - 获取 .Net XML 文档以返回字典的特定类型

java - PHP DateTime到Java Date

.Net 3.5 WebService 不能被 .Net 1.1 Windows App 调用

c# - 将文件添加到现有Zip中-性能问题

c# - 如何在 C# 中发现 onvif 设备

c# - axWindowsMediaPlayer 的方法 setMode ("showFrame",true) 在 Windows 7 的 WMP 12 中不起作用

c# - Entity Framework 日期组合查询

java - 如何在不使用默认身份 validator 的情况下使用 JAXWS 访问受密码保护的 WSDL?

c# - WCF 中的异步流