.net - 在 IIS 中运行时 WCF 服务无法连接到 Web 服务

标签 .net wcf web-services ssl iis-5

我有一个 WCF 服务,它被用作我们正在集成的第三方 asmx 服务的包装器。它正在与之通信的服务是使用 Visual Studio 中的“添加服务引用”对话框添加的。 WCF 服务中的代码在单元测试中执行时有效,在调试主机应用程序时也有效。

当调试主机在 ASP.NET 开发服务器中运行时,它可以正常工作。当我将应用程序部署到本地 IIS 实例(与开发机器 IIS 5.1 相同)时,服务将启动并运行,但在连接第三方 asmx 端点时会抛出此错误:

System.ServiceModel.Security.SecurityNegotiationException: 
Could not establish trust relationship for the SSL/TLS secure channel with
authority 'xxxxx.thirdparty.com'. ---> 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.

这些是服务端点配置文件中的设置:

<basicHttpBinding>
  <binding name="ServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
    useDefaultWebProxy="false" proxyAddress="http://[internalWebProxyHere]">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
    <security mode="Transport">
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
      <message clientCredentialType="UserName" algorithmSuite="Default"/>
    </security>
  </binding>
</basicHttpBinding>

该服务在 visual studio 中工作,但在部署到 IIS 后就不行了。如何调试 AuthenticationExceptions?

编辑:客户端端点如下所示:

<endpoint address="https://'xxxxx.thirdparty.com/thirdpartyendpoint.asmx" 
    binding="basicHttpBinding" bindingConfiguration="ServiceSoap" 
    contract="eContracting.ServiceSoap" name="ServiceSoap"
    behaviorConfiguration="Behavior"/>

我尝试添加端点行为来禁用证书验证,但这没有帮助:

<behavior name="Behavior">
  <clientCredentials>
    <serviceCertificate>
      <authentication certificateValidationMode="None"/>
     </serviceCertificate>
    </clientCredentials>
</behavior>

如果它也有助于第三方证书是由 Rapid SSL CA 颁发的,则该证书有效。在我的本地证书存储中查看此证书位于“中间证书颁发机构”选项卡中,但不在“受信任的根证书颁发机构”或“受信任的发布者”中。

编辑:通过将证书添加到“受信任的根证书颁发机构”解决了这个问题,尽管有一个问题。

  1. 从控制面板导入证书 -> InternetProperties -> 内容 -> 证书。如果您以这种方式安装,它会说它是成功的,但它不会显示在 winhttpcertcfg 中。
  2. 导入证书,方法是开始 -> 运行 -> 输入“certmgr.msc”并通过此处安装。它会说导入成功,但证书不适用于 winhttpcertcfg。
  3. 通过开始 -> 运行 -> MMC 导入证书并使用证书管理单元确实有效。点击here查看适用于 Windows XP 的说明。

具体来说,这是有效的:

  1. 开始 -> 运行 -> MMC
  2. 文件 -> 添加/删除管理单元
  3. 点击添加...
  4. 选择证书并点击添加
  5. 选择计算机帐户并单击下一步
  6. 选择本地计算机并点击完成
  7. 点击关闭
  8. 将证书从控制台根目录导入到这些位置:

    • 受信任的根证书颁发机构
    • 中级证书颁发机构
    • 第三方根证书颁发机构

最佳答案

尝试在服务 web.config 中启用跟踪。通过将 switchValue 设置为 Verbose,您可能能够找出更详细的错误。可能证书有问题。

Configure and Enable Tracing

您也可以尝试将服务证书验证模式设置为无。

X509ServiceCertificateAuthentication.CertificateValidationMode Property

另一种选择是将 Rapid SSL CA 导入本地计算机上的受信任的根证书颁发机构。我怀疑 cassini 没有验证或忽略证书。

另一个可能需要注意的问题是,为您的服务运行 IIS 的帐户可能没有从证书存储中读取的权限。

关于.net - 在 IIS 中运行时 WCF 服务无法连接到 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11527598/

相关文章:

web-services - 进行搜索查询并获得结果

.net - 在 SSH.NET 中检查 SFTP/SSH 指纹

c# - 如何在 bootstrap alert -bootstrap MVC 中插入换行符

.net - FIDO 2.0 WebAuthn 库能否用于与 FIDO 1.0 UAF 通信?

c# - 以编程方式分离 SQL Server 数据库以复制 mdf 文件

WCF 服务引用创建第二类

java - axis2 网络服务。在哪里放置我自己的配置

java - Android 发布应用程序市场自动执行购买后任务

wcf - 在IIS/WAS中托管的非HTTP WCF服务中初始化代码的正确位置?

WCF Web 服务和 SSL 和证书