1

我有一个 WCF 服务托管在我的 Server1 上的 Windows 服务上。这台机器上也有 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" 有关?

4

2 回答 2

2

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

谢谢 !

于 2010-03-29T14:12:04.443 回答
1

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

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

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

于 2010-03-25T16:17:00.903 回答