tags:

views:

219

answers:

2

Hello,

Please help me, how to change endpoint address programatically in the client site?

Thanks

+2  A: 
proxy.Endpoint.Address = new EndpointAddress("http://newaddress");

where proxy is an instance of the client class generated when importing the WSDL. Or you can specify the address when creating the client proxy:

var endpoint = new EndpointAddress("http://newaddress");
var proxy = new SomeClientProxy("BasicHttpBinding_IHelloWorld", endpoint);
Darin Dimitrov
you actually **cannot** change the endpoint after the proxy has been created - you must do this before calling the first method on your proxy.
marc_s
Good point @marc_s. Does this mean that the first example I gave won't work or it will work only if done before calling the first method?
Darin Dimitrov
@Darin: I think it'll throw an exception if you try to do it after a method on the service has already been called (not 100% sure though). Best practise is to always do these setup things first before any calls :-)
marc_s
A: 

http://deadkota.wordpress.com/2010/06/23/wcf-client-change-endpoint-address-dynamically/

using(abcServiceClient proxy = new ABCServiceClient()) { proxy.Endpoint.Address = new System.ServiceModel.EndpointAddress("net.tcp://localhost:8082/ABCService"); proxy.Open(); proxy.Function(); }

prashant