Search code examples
c#wcfwcf-client

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 generated in the app.config but changing the address?) and how do you configure the client to use a particular endpoint?


Solution

  • 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));