【问题标题】:Calling a WCF service from another WCF service从另一个 WCF 服务调用 WCF 服务
【发布时间】:2011-01-31 18:44:51
【问题描述】:

我的 Server1 上的 Windows 服务上托管了 WCF 服务。这台机器上也有 IIS。我从网络应用程序调用该服务,它工作正常。但在此服务中,我必须调用位于 Server2 上的另一个 WCF 服务(也托管在 Windows 服务上)。安全凭证设置为“消息”和“用户名”。我有一个类似“SOAP 协议协商失败”的错误。这是我的服务器证书公钥似乎无法识别的问题。但是,如果我在控制台应用程序中从 Server1 调用 Server2 上的服务,它就可以正常工作。

我按照本教程设置我的证书:http://www.codeproject.com/KB/WCF/wcf_certificates.aspx

这是我在 Server1 上尝试调用第二个服务的配置文件:

    <endpoint address=""
              binding="wsHttpBinding"
              contract="Microsoft.ServiceModel.Samples.ITraitement" />


    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>

</services>

<client>
  <endpoint address="http://Server2:8000/servicemodelsamples/service"
    behaviorConfiguration="myClientBehavior" binding="wsHttpBinding"
    bindingConfiguration="MybindingCon" contract="Microsoft.ServiceModel.Samples.ICalculator"
    name="">
    <identity>
      <dns value="ODWCertificatServeur" />
    </identity>
  </endpoint>
</client>

<bindings>
  <wsHttpBinding>
    <binding name="MybindingCon">
      <security mode="Message">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceTraitementBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="myClientBehavior">
      <clientCredentials>
        <clientCertificate findValue="MachineServiceTraitement" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />
        <serviceCertificate>
          <authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck"/>
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

这是调用 Server1 上服务的 Web 应用程序的配置文件:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_ITraitement" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
          enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
            algorithmSuite="Default" establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:8020/ServiceTraitementPC"
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITraitement"
      contract="ITraitement" name="WSHttpBinding_ITraitement">
  </endpoint>
</client>

如果我在控制台应用程序中而不是从我的服务中调用它,知道为什么它会起作用吗?也许它与 certificateValidationMode="ChainTrust" 有关?

【问题讨论】:

  • 你也有 server2 的配置吗?
  • 这个问题你解决了吗?

标签: wcf wcf-security x509certificate


【解决方案1】:

好吧,最后只是信任客户端计算机上的证书颁发者的问题。教程中提到了它,我一定错过了那一步。仍然想知道为什么从控制台应用程序调用时它会起作用,但是……无论如何,它现在可以正常工作了。

谢谢!

【讨论】:

    【解决方案2】:

    当您从控制台应用程序调用服务时,您处于登录用户的安全上下文中。

    当您从运行在 IIS 中的服务调用该服务时,使用默认设置,您处于本地帐户 NETWORK SERVICE 的安全上下文中。

    修复它的方法可能是在 web.config 的 system.web 部分设置 impersonate=true。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 2019-03-06
      • 2014-12-01
      • 2017-04-07
      • 2017-04-09
      相关资源
      最近更新 更多