C# 客户端到 SoapUI https 模拟服务:无法为具有权限 'localhost:8083' 的 SSL/TLS 安全通道建立信任关系

C# client to SoapUI https mock service: Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost:8083'

我有一个简单的 C# 程序需要与第 3 方 SOAP Web 服务 ("FooService") 通信。

我将 WSDL 导入 Visual Studio 并创建了一个服务引用。我的 C# 客户端代码如下所示:

  FooSoapClient webService = new FooSoapClient ();
  webService.Endpoint.Address = new EndpointAddress(cbWsUrl.Text);
  bool response = webService.PutDocumentCollection(docs);

我将相同的 WSDL 导入 SoapUI,创建了一个模拟服务和一个模拟响应,我的 C# 客户端能够与 SoapUI 成功通信:

问题:

这一切都适用于 http ...但不适用于 https

我按照本指南使用 java keytool 创建了我自己的带有自签名证书 (alias soapui) 的小型密钥库 (mock.keystore) 并配置了 SoapUI将其用于 https(端口 8083):

现在我的 C# 客户端失败了:

01/09/18 17:11:24: ERROR:Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost:8083'.
System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost:8083'. 
---> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. 
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

解决方法:

我添加了 ServerCertificateValidationCallback 以禁用所有证书检查:

ServicePointManager.ServerCertificateValidationCallback =
  (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
  return true;

问题:

我应该怎么做才能让我的 C# 程序 "trust" SoapUI,以便我可以 "connect" 使用 https?

有什么方法可以 "import" 证书吗?

换句话说:

问:当您 "Add Exception" 访问 https 站点时,我需要做什么才能使我的独立 C# 应用程序像浏览器一样运行?

注意:没有任何类型的身份验证:我只是想通过 https 连接到 SoapUI。

如果您使用自签名证书进行测试,您可以将其导入 Trusted Root Certification Authorities 存储 运行 应用程序和它的用户将被 Windows 和 .NET 视为信任。 在 WCF 文档的以下文章中,您有更详细的指南如何安装证书。 Installing a Certificate in the Trusted Root Certification Authorities Store