当WCF客户端为同一合同指定多个终结点时会发生什么? [英] What happens when a WCF client specifies multiple endpoints for the same contract?

查看:137
本文介绍了当WCF客户端为同一合同指定多个终结点时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有这些都会消耗掉吗?
会抛出异常吗?

Will it consume from all of them? Will it throw an exception?

推荐答案

您可以在同一个合约中有多个终结点,而同一个合约中有不同的地址配置,没问题。

You can have multiple endpoints for the same contract and different addresses in your clieint config, no problem.

它们必须由<$ c $上的唯一 name = 属性分隔c><端点> 标签。

They need to be separated by a unique name= attribute on the <endpoint> tag.

<client>
  <endpoint name="tcpEndpoint"
            address="net.tcp://server:8888/SomeService"
            binding="netTcpBinding"
            contract="IYourService" />
  <endpoint name="httpEndpoint"
            address="http://server:8777/SomeService"
            binding="basicHttpBinding"
            contract="IYourService" />
</client>

创建客户端代理时,需要提供要使用的端点名称:

When you create your client proxy, you need to provide the name of the endpoint you want to use:

YourClient client = new YourClient("netTcpEndpoint");

您不能再仅实例化您的客户端并期望它找到要使用的端点,因为有多个(不幸的是,如果没有指定,则无法将其中一个定义为默认,它将被使用)。

You can no longer just instantiate your client and expect it to find "the" endpoint to use, since there are multiple (and there's no way to define one as the "default" which gets used if nothing is specified, unfortunately).

除此之外-不会出现问题,我想。

Other than that - no problems should arise, I think.

这篇关于当WCF客户端为同一合同指定多个终结点时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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