我正在尝试使用 wcf 通过相互证书进行 SOAP 调用,但还是不断出错
“请求已中止:无法创建 SSL/TLS 安全通道。” 或
'远程服务器返回错误:(500) 内部服务器错误缺少 wsse: 请求中的安全 header '
在 SOAP UI 中完成的类似请求有效,但 n C# 不想通过。我还查看了发送的确切内容,发现 soap envolope 确实在 header 中缺少 wsse:Security。我怎样才能让它发挥作用?
WSHttpBinding myBinding = new WSHttpBinding();
myBinding.Security.Mode = SecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
EndpointAddress ea = new EndpointAddress("https://[securedEndpoint]/Calculator");
CalculatorClient cc = new CalculatorClient(myBinding, ea);
cc.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser,
StoreName.Root,
X509FindType.FindBySerialNumber,
"37802b632e74e355");
cc.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.CurrentUser,
StoreName.Root,
X509FindType.FindBySerialNumber,
"29f3e22fc1ae45be");
// Begin using the client.
try
{
cc.Open();
Console.WriteLine(cc.Add(200, 1111));
Console.ReadLine();
// Close the client.
cc.Close();
}
最佳答案
如您所知,当我们使用证书来保护通信时,我们应该将证书绑定(bind)到特定的端口。此外,如果我们使用证书对客户端进行身份验证,则必须在服务器证书和客户端证书之间建立证书信任关系。除了Message安全模式,我们一般在客户端提供一个客户端证书即可。
我建议你检查客户端和服务器端之间的信任关系状态。此外,为了保证证书可用,我们最好使用本地机器证书存储和证书指纹设置证书。考虑到证书私钥的访问问题,建议大家将Everyone账号添加到证书私钥管理组。
最后请确保证书具有客户端认证和服务器认证的预期目的。
如果有什么我可以帮忙的,请随时告诉我。
关于c# - 缺少相互证书的 Wcf 请求 wsse :Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58358536/