Search code examples
c#wcfconsole-applicationservice-referencesvc

Variable Service Reference Endpoint in C# and Visual Studio


Excuse my ignorance if this is something basic, I am somewhat new to the whole C# console application, using a Web Service Reference (WCF).

I am creating an application that will be places as an executable on many different machines and acts as a client to a web service. however, the web service is also installed in the client's local intranet, so the endpoint will change for each location.

I see the web reference endpoint is in the app.config file when adding within Visual Studio, but is there a simple way to change the endpoint at runtime, verify the endpoint is correct and exists, and be able to use the methods?

Also, if this is possible would I still need to add the SVC as a service reference in my Solution or would I call it dynamically?

I am using C# and .Net 4

Thanks


Solution

  • You can put the address as an AppSetting and set it after creating your proxy class:

    Proxy.Endpoint.Address = new EndpointAddress("myconfigvaluehere");