我正在尝试使用另一家公司发布的服务。关于认证和通信的规范是:
- 肥皂
- 带有双向 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;”
- 在 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/