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

三世轮回 提交于 2019-12-19 19:14:00

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/1888233/what-happens-when-a-wcf-client-specifies-multiple-endpoints-for-the-same-contrac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!