WCF 调用另一个 WCF:无法建立 SSL/TLS 的信任关系

发布于 2024-12-29 23:04:15 字数 380 浏览 2 评论 0原文

我有两个 WCF 托管在两个不同的 HTTPS 网站上,并且具有不同的证书。 WCF(a) 使用 if 子句调用 WCF(b),反之亦然,以取消可能的无限循环。

每次调用两个 WCF 的方法时,都会返回错误:

Could not establish trust relationship for the SSL/TLS

我尝试在受信任的根证书中安装证书,但错误仍然出现。不幸的是,避免 WCF 调用另一个 WCF 并不是一种选择。

有什么解决办法吗?

更新:

我尝试在同一个网站上托管这两个网站并且它有效,所以我认为这是特定于所使用的证书的?那么是否必须使用同一个证书呢?或者是否有可能使用具有不同证书的不同网站?

I have two WCF hosted on two different HTTPS websites with different certificates. WCF(a) calls WCF(b) and vice-versa with an if clause to cancel the possible infinite loop.

Every time the method of both WCF is called, it returns the error:

Could not establish trust relationship for the SSL/TLS

I tried installing the certificates in the Trusted Root Certificates but the error still appears. Avoiding the WCF-calling-another-WCF is not an option, unfortunately.

Any fix for this?

UPDATE:

I've tried hosting both in the same website and it worked so I'm thinking this is specific to the certificate being used? So should the same certificate must be used? or is there a possible way to use different websites with different certificates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清晰传感 2025-01-05 23:04:15

当您使用自签名证书时,您需要让访问 WCF 服务的客户端中的证书验证返回 true。

代码如下所示:

System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
                                                                                     {
                                                                                         return true;
                                                                                     };

只需在调用服务方法之前放置此代码即可。

另外,由于您有 2 个服务 A 和 B 相互调用,因此当您拨打电话时,上述代码应该位于两个地方。以上是信任证书,因为它不是来自受信任的证书提供商。

When you use self signed certificates you need to have the certificate validation return true in your client that access the WCF service.

The code is as shown below:

System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
                                                                                     {
                                                                                         return true;
                                                                                     };

Just place this code before you invoke your service method.

Also Since you have 2 services A and B calling each other the above code should be in both places when you make a call. The above is to trust the certificate as its not from a trusted certificate provider.

与往事干杯 2025-01-05 23:04:15

使用 SSL 自签名证书时,您需要注意以下事项:

  1. 证书需要安装在 LocalHost\My 和 LocalHost\CA 存储中。
  2. 主题中的公用名部分需要与服务器的完全限定域名相匹配。对于自签名证书,您可以使用公共 IP 地址。
  3. 您的服务运行所使用的帐户必须具有对证书私钥的读取访问权限。

可以通过将服务托管在 IIS 下并使用 IIS 生成服务器证书来满足这些步骤。

另请注意,wcf 通常要求将 CRL 附加到证书。但这也可以使用 certmgr.exe 生成。

Using self signed certificates for SSL you need to be aware of the following:

  1. The certificate needs to be installed in both LocalHost\My and LocalHost\CA stores.
  2. The common name part in the subject needs to match the fully qualified domain name for the server. For self signed certificates you can use the public ip address.
  3. The account that your service runs under must have read access to the private key of the certificate.

These steps can be satisfied by hosting the services under IIS, and use IIS to generate the server certificate.

Also be aware that wcf usually requires that an CRL is attached to the certificate. But this can also be generated with certmgr.exe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文