WCF客户端使用多个服务

时间:2010-03-24 17:14:12

标签: wcf basichttpbinding

我正在试图弄清楚如何设置我的web.config(客户端)以使用另一个使用

来使用两个不同的WCF Web服务

我有两个端点,我想我需要两个不同的Binding配置。这是我当前的绑定节点:

<basicHttpBinding>
    <binding name="WebServiceProxyServiceSoapBinding" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <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>

我无法添加另一个basicHttpBinding节点。问题是,如果我改变的是<security mode="Transport">中的模式参数,那么绑定对于一个或另一个端点将起作用。

这似乎是一个常见问题,但尚未找到答案。总的来说,在简单的消费和调用之外,我对WCF(如果不是很明显)的体验并不是很好。任何帮助都会很棒!

这篇文章很接近但不完全相同,因为它们不需要不同的安全模式: How to consume multiple WCF services from one client

提前致谢。

2 个答案:

答案 0 :(得分:8)

您只需在<binding>节点下添加另一个<basicHttpBinding>节点,其中包含不同的名称和您喜欢的任何其他选项。

然后,显然,只需通过在每个bindingConfiguration节点的<endpoint>属性中设置适当的名称,确保每个客户端都配置为使用特定于它们的绑定。

答案 1 :(得分:2)

  

我有两个端点,我猜我   需要两个不同的绑定   配置。这是我的最新消息   绑定节点:

不一定 - 如果这两个服务使用相同的设置和相同的协议,一个绑定配置就可以。

你需要添加两个是客户端元素:

<system.serviceModel>
   <bindings>
       ..... (as you already have it) ....
   </bindings>
   <client>
      <endpoint name="Service1Endpoint"
                address="http://yourserver/service1.svc" 
                binding="basicHttpBinding"
                bindingConfiguration="WebServiceProxyServiceSoapBinding"
                contract="IWCFService1"  />
      <endpoint name="Service2Endpoint"
                address="http://yourserver/service2.svc" 
                binding="basicHttpBinding"
                bindingConfiguration="WebServiceProxyServiceSoapBinding"
                contract="IWCFService2"  />
   </client>
</system.serviceModel>

应该这样做。

当然,如果您的第二个服务使用另一个绑定,或者需要不同的安全设置,那么是的,您需要在<binding name="something else" .....>节点下添加第二个<basicHttpBinding>并引用该第二个绑定配置来自您的两个客户端端点之一。

相关问题