开发者

What happens when a WCF client specifies multiple endpoints for the same contract?

开发者 https://www.devze.com 2022-12-14 06:19 出处:网络
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.

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消