tags:

views:

46

answers:

3

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?

A: 

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.

Steve Danner
+1  A: 

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));
Eugene Cheverda
I"m not sure what you mean. Does this happen serverside? The service is already running on the server, I'm trying to access it locally depending on the location of the client (LAN or remote).
SnOrfus
I mean that this code sample is running on client. You should define any number of endpoints you need at app.config or string resources and then required endpoint address pass as the parameter to the service's constructor. Location you may define as any preferable condition at client.
Eugene Cheverda
+2  A: 

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.

KeithS
Believe me, I'd love to do that, but DNS resolution/forwarding isn't set up at the server, and getting the sysadmin to fix it is just 'not gonna happen'. Even accessing exchange webmail requires either company.com/mail via internet or serverName/mail via LAN. Using company.com/mail whilst on the LAN results in 404. From what you're saying though, it sounds like I can't have multiple endpoints? I have to create them at runtime in this situation?
SnOrfus
You don't have to "create" them at runtime; you have to specify the one to use at runtime. Really, there is one endpoint to the service, which you're accessing via two different IP addressing schemes (your LAN subnet and the Internet). Which address you use depends on where your client computer is on the network, and you can tell the client which to use by specifying it in the app.config.
KeithS