Question

I have some doubts about using Service References for an application that will be deployed to different customers. It's a WCF service on vb.net that will be hosted in a Windows Service, and it will be used by very different customers with different IP Addresses. Different environments, so to speak.

I've already made the server and the client. They work just fine using Service References on the client, but since these need the URL of the service (which will have this structure: net.tcp://SomeHost:6666/SomeService), the question is: what can I do to use the Service References on the customer's environment? I'm thinking about something like changing its URL programatically, but I don't know if it's possible.

Of course, the hostname will change from customer to customer, but the Service References are static. I thought of using a different approach, such as: http://mstecharchitect.blogspot.com.ar/2009/01/invoking-wcf-service-without-service.html. But this would make me lose the benefits of the Service Reference, which, as I understand, creates the needed proxy so I can use it on the client side.

Whatever else information you need to help me, don't hesitate to ask. And thanks in advance!

Was it helpful?

Solution

You can store in config file (appsettings, for example), your service endpoint address, when in code you'll update only the host name.

Your appsettings will contain something like net.tcp://{0}:6666/SomeService.

When creating client's (proxy) instance - you'll add specific host and pass this built address.

Something like:

app.config on client:

  <appSettings>
    <add key="YourService.ClientAddress" value="net.tcp://{0}:6666/SomeService" />
  . . .

then, in the code,

    string endpointUrl = string.Format(ConfigurationManager.AppSettings["YourService.ClientAddress"], Your_Host_name);
    YourClient client = new YourClient(YourEndpointName, endpointUrl);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top