简体   繁体   English

多个客户端端点指向同一WCF服务

[英]Multiple client endpoints to the same WCF service

I've got a WCF service running on a LAN IIS which is accessible from the internet as well. 我有一个在LAN IIS上运行的WCF服务,也可以从互联网访问。

The client that consumes the service is an application that runs on the LAN and remotely through the internet. 使用该服务的客户端是在LAN上运行并通过Internet远程运行的应用程序。 There is no forwarding of anything on the DNS server redirecting http://www.corporate.com/Service to http://serverName/Service so I'm figuring I'll need 2 endpoints on the client. 在DNS服务器上没有任何转发将http://www.corporate.com/Service重定向到http:// serverName / Service,所以我想在客户端上需要2个端点。

How do you setup multiple endpoints in the client (is it as simple as copying the existing enpoint generated in the app.config but changing the address?) and how do you configure the client to use a particular endpoint? 如何在客户端中设置多个端点(它是否像复制app.config中生成的现有enpoint一样简单但更改地址?)以及如何配置客户端以使用特定端点?

You may store endpoint addresses either at app.config, or at resource strings. 您可以在app.config或资源字符串中存储端点地址。 Then using any condition you pass needed endpoint address to service constructor. 然后使用任何条件将所需的端点地址传递给服务构造函数。

var endpoint = ApplicationSettings.IsRemote ? Resources.RemoteEndPoint: Resources.LocalEndPoint;
var service = new MyWCFService(new BasicHttpBinding(), new Endpoint(endpoint));

The app.config (or web.config) for each copy of the application should have the endpoint for the service set based on the one it needs. 应用程序的每个副本的app.config(或web.config)应该具有基于其所需服务集的端点。 For LAN installations, use the LAN-visible endpoint; 对于LAN安装,请使用LAN可见端点; for all others, use the Internet one. 对于所有其他人,请使用互联网。

It may save you a trip to the router, but why not just use the internet endpoint everywhere? 它可以为您节省路由器之旅,但为什么不在任何地方使用互联网端点? If your LAN computers have a gateway to the Net, they can see the externally-visible address. 如果您的LAN计算机具有到网络的网关,则可以看到外部可见的地址。

It is as simple as changing the address and using the endpoint generated in the app config. 它就像更改地址和使用app config中生成的端点一样简单。 You may have to change security modes depending on what is supported on either server, or whether they are both running HTTPS or not. 您可能必须更改安全模式,具体取决于任一服务器上支持的内容,或者它们是否都运行HTTPS。 We have an application where we build the target endpoint based on relative path to the current URL in a Silverlight application. 我们有一个应用程序,我们根据Silverlight应用程序中当前URL的相对路径构建目标端点。 We also dynamically change the security mode based on HTTPS being present and it works great. 我们还根据存在的HTTPS动态更改安全模式,并且效果很好。

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

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