从另一个 WCF 服务调用 WCF 服务 [英] Calling a WCF service from another WCF service

查看:38
本文介绍了从另一个 WCF 服务调用 WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a WCF service hosted on a windows service on my Server1. It also has IIS on this machine. I call the service from a web app and it works fine. But within this service, I have to call another WCF sevice (also hosted on a windows service) located on Server2. The security credentials are set to "Message" and "Username". I have an error like "SOAP protcol negociation failed". It's a problem with my server certificate public key that doesn't seem to be recognise. However, if I call the service on the Server2 from Server1 in a console app, it works fine.

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

I followed this tutorial to set up my certificates : http://www.codeproject.com/KB/WCF/wcf_certificates.aspx

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

Here's the config file from my service on Server1 that tries to call the second one :

    <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 应用程序的配置文件:

And here's the config file from the web app that calls the service on Server1 :

<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"有关?

Any idea why it works if if I call it in a console app and not from my service ? Maybe it has something to do with the certificateValidationMode="ChainTrust" ?

推荐答案

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

Well, finally it was just a matter of trusting the issuer of the certificate on the client machine. It was mentioned in the tutorial and I must have missed that step. Still wonder why it worked when calling from a console app, but... anyway, it works fine now.

谢谢!

这篇关于从另一个 WCF 服务调用 WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆