【问题标题】:WCF Client consuming multiple servicesWCF 客户端使用多个服务
【发布时间】:2010-03-24 17:14:12
【问题描述】:

我正在尝试弄清楚如何设置我的 web.config(客户端)以使用两个不同的 WCF Web 服务,一个使用另一个使用

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

<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 节点。问题是,如果我更改的只是 &lt;security mode="Transport"&gt; 中的模式参数,那么绑定将适用于一个或另一个端点。

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

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

提前致谢。

【问题讨论】:

    标签: wcf basichttpbinding


    【解决方案1】:

    您只需在&lt;basicHttpBinding&gt; 节点下添加另一个&lt;binding&gt; 节点,使用不同的名称和您喜欢的任何不同选项。

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

    【讨论】:

    • :) 这太容易了。谢谢!
    【解决方案2】:

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

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

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

    <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>
    

    应该可以。

    当然,如果您的第二个服务使用另一个绑定,或者需要不同的安全设置,那么是的,您需要在您的 &lt;basicHttpBinding&gt; 节点下添加第二个 &lt;binding name="something else" .....&gt; 并从您的一个节点中引用第二个绑定配置这里有两个客户端端点。

    【讨论】:

    • 噢,我看到我试图添加第二个 节点,而不是第二个子 Binding 节点!谢谢!
    猜你喜欢
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2010-10-15
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多