开发者

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.

The client that consumes the service is an application that runs on the LAN and remotely through the 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.

How do you setup multiple endpoints in the client (is it as simple as copying the existing enpoint generate开发者_运维知识库d in the app.config but changing the address?) and how do you configure the client to use a particular endpoint?


You may store endpoint addresses either at app.config, or at resource strings. 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. For LAN installations, use the LAN-visible endpoint; 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.


It is as simple as changing the address and using the endpoint generated in the 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. We have an application where we build the target endpoint based on relative path to the current URL in a Silverlight application. We also dynamically change the security mode based on HTTPS being present and it works great.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜