Question

I'm using a Web Service that has a endpoint of http://api.domain_a.com/ and using Visual Studio I can easily generate a proxy class to work with the service easy and simple.

alt text

But I want to create a way that users can use their own service (and access their own data, instead my own) and I wanted to know if there is a way that I can change the base URL of the Service on-the-fly.

As an example

I generate the proxy classes by adding the Web References to my project, but now, per each request I have a User Name that I will get the User Settings (witch contains their URL), how can I (if it's a possibility) tell the generated proxy that I'm using domain http://domain_b.com/api instead of the original that I used when adding the Web References?

Do I need to call the service manually? Sending and Receiving XML data? or there is a "switch" that I can use to point to the new URL?

Was it helpful?

Solution

If you're using .NET 2.0, each of those proxy classes should have a URL property. Simply update the URL property and the proxy will point to the new service.

If you're using WCF then things get a little more complicated, but not by much. You just have to change the Endpoint Address:

var service = new ServiceClient();
string url = "http://domain_b.com/api";
EndpointAddress newAddress = new EndpointAddress(url);
service.Endpoint.Address = newAddress;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top