简体   繁体   English

有没有办法迭代潜在的WCF服务器端点?

[英]Is there a way to iterate over potential WCF server endpoints?

In a WCF server/client situation, the WCF configurations on both server and client have to be synchronized. 在WCF服务器/客户端情况下,必须同步服务器和客户端上的WCF配置。 Eg In a situation where my client has the configuration below, the server has to have the same binding name, contract and configuration, or it won't connect properly. 例如,在我的客户端具有以下配置的情况下,服务器必须具有相同的绑定名称,合同和配置,否则它将无法正确连接。

<bindings>
   <basicHttpBinding>
       <binding name="ServerContract" />
   </basicHttpBinding>
</bindings>
<client>
   <endpoint address="http://localhost/.../ServerContractImpl.svc/Mtom"
            binding="basicHttpBinding" bindingConfiguration="ServerContract"
            contract="ServerReference.ServerContract" name="ServerContract" />
</client>

I'm writing WCF client code for a server whose configuration I don't control, and this requirement makes me very nervous. 我正在为我无法控制其配置的服务器编写WCF客户端代码,这一要求使我非常紧张。 I've generated my initial client configuration using VS2010's Service Reference, but if at any time the admin of the server changes, say, their binding names, how would my WCF client respond to that? 我已经使用VS2010的服务参考生成了初始客户端配置,但是如果服务器的管理员在任何时候更改了绑定名称,我的WCF客户端将如何响应呢?

So my questions: 所以我的问题是:

  • How does a WCF client, assuming it has the URL to the server's .svc endpoint address, find out which endpoints and bindings are active on the server and connect to whichever one of them it chooses? 如果WCF客户端具有指向服务器的.svc端点地址的URL,如何如何找出服务器上处于活动状态的端点和绑定,并连接至它选择的任意一个?
  • How are situations such as these, where the WCF server and client are controlled by different people, usually managed in terms of WCF configuration? 在这种情况下,通常由WCF配置来管理WCF服务器和客户端由不同人员控制的情况?

I asked a somewhat related question a few weeks ago: WCF endpoint discovery from a client; 几周前,我问了一个相关的问题: 从客户端发现WCF端点; Is it possible? 可能吗?

From the answer: 从答案:

The following MSDN article should address your concern, as it clearly states that a client must have prior knowledge of the service address prior to discovery. 以下MSDN文章应解决您的问题,因为它清楚地指出,客户端必须在发现之前先了解服务地址。

The answer includes a link to this article which is pretty informative and might address what you're looking for: http://msdn.microsoft.com/en-us/magazine/ee335779.aspx 答案包括指向该文章的链接,该文章内容丰富,可能会满足您的要求: http : //msdn.microsoft.com/zh-cn/magazine/ee335779.aspx

From the article: 从文章:

It would be great if the service could use any available address. 如果服务可以使用任何可用地址,那就太好了。 The client, in turn, would need to discover that address at runtime. 反过来,客户端将需要在运行时发现该地址。 In fact, there is an industry standard-based solution that stipulates how that discovery takes place. 实际上,有一个基于行业标准的解决方案规定了如何进行发现。 That solution, called simply discovery (and its supporting mechanisms), is the subject of this column. 该解决方案称为简单发现(及其支持机制),是本专栏的主题。

In my opinion this is more like a best practice thing. 我认为这更像是一种最佳实践。 If you have no prior knowledge about the server you are about to connect to, the best thing is to prevent the worst to happen. 如果您对要连接的服务器没有任何先验知识,那么最好的办法就是防止最坏的情况发生。

You can develop an exception mechanism to fail over one endpoint to another endpoint. 您可以开发异常机制以将一个端点故障转移到另一端点。 The exception you expect to catch include CommunicationException and FaultException, both are under the Service.ServiceModel namespace. 您希望捕获的异常包括CommunicationException和FaultException,它们都在Service.ServiceModel命名空间下。

Secondly as the other user said, get better knowledge of the WCF server side see if they enable WCF discovery. 其次,就像另一个用户所说的那样,对WCF服务器端有更好的了解,看看他们是否启用WCF发现。 WCF discovery allow you decouple your WCF client and the address it connects to. WCF发现使您可以将WCF客户端与其连接的地址分离。 In case of service failure/migration your client (yourself) can automatically connect to a proper address without failure. 如果发生服务故障/迁移,您的客户端(您自己)可以自动连接到正确的地址而不会发生故障。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM