【发布时间】:2019-12-11 08:33:52
【问题描述】:
我正在尝试向使用 SSL 证书进行通信的 Web 服务端点发出请求。我花了几个小时在谷歌上搜索一个例子,但到目前为止几乎没有。
我确实设法通过直接导航到 wsdl 和 xsd 文件、手动保存它们并将 WCF Web 服务引用提供程序指向基于this 解决方案的包含目录来使连接的服务成为脚手架。我还尝试使用 winhttpcertcfg.exe 安装证书,但无法使用该工具成功打开通道以直接从 WSDL 生成客户端。
现在我已经生成了客户端,但我无法弄清楚如何正确添加证书。这是我目前拥有的代码
// Get the certificate
var testCert = new X509Certificate2(System.IO.File.ReadAllBytes("C://SecureCert.PFX"), "##########");
//Create instance of SOAP client
HostedCollectionPaymentService.OnlineService_v2_2Client soapClient = new OnlineService_v2_2Client(new BasicHttpsBinding(BasicHttpsSecurityMode.Transport), new EndpointAddress("https://secure.service.endpoint.com/2.2/"));
// Add the certificate to the client
soapClient.ClientCredentials.ClientCertificate.Certificate = testCert;
using (new OperationContextScope(soapClient.InnerChannel))
{
try
{
var result = await soapClient.startOnlineCollectionAsync(new StartOnlineCollectionRequest
{
app_id = "12344",
tracking_id = "fdsa43531",
transaction_amount = 5.00m,
transaction_type = TransactionType.Sale
});
Console.WriteLine(result.startOnlineCollectionResponse.token);
}
catch (Exception ex)
{
var f = ex;
throw;
}
}
当我尝试连接时,我收到响应“消息 =”无法为 SSL/TLS 安全通道建立信任关系,授权为 'secure.service.endpoint.com'”。
我已验证证书有效,并且我能够使用 SoapUI 工具集连接到服务。
我假设我缺少配置或错误地附加了 SSL 证书。如果有人可以提供建议或向我指出适当的文档,我将不胜感激。
【问题讨论】:
标签: c# ssl asp.net-core soap certificate