Rajagopalk
Rajagopalk

Reputation: 31

How to Change WCF Service endpoints?

i having more than Three web services, In that one is master site,and Others are client sites.

In My User Interface One Text box is Available ,In that text box i need to give Destination End Point address from that Text box Value i need call the Client Service.

for Example:

Client1 end point Service Name:

                 http://localhost:1524/WebServiceService.svc" 

Client2 end point Service Name:

By

Rajagopalk

                 http://localhost:8085/WebServiceService.svc" 

if i give "localhost:1524" in Text box Client1 Service will call, if i give "localhost:8085" in Text box Client2 Service will call,

Upvotes: 3

Views: 10256

Answers (1)

marc_s
marc_s

Reputation: 754230

Are you hosting your WCF services in IIS ? In that case, your service address is determined by the IIS configuration and the virtual directory where your service's *.svc file exists.

So to change something on the server, you need to check and modify the IIS configuration.

To change on the client side, there's a web.config (for ASP.NET webs) or an (applicationName).exe.config where your endpoint definition should be contained - change the endpoint address there:

<client> 
   <endpoint name="YourEndpointName"
       address="http://localhost:8085/WebServiceService.svc" 
       binding="......." bindingConfiguration="............."
       contract="..................." />
</client>

You need to specify the complete target web service address in the address= attribute of your <endpoint> configuration element.

You can define multiple endpoints for the same service, and pick which one to use when you instantiate the client proxy:

MyServiceProxy client = new MyServiceProxy("name of endpoint configuration");

and with this, you can switch between several definitions of endpoints easily.

UPDATE: If you want to programmatically set your client address from code, you need to do the following when creating your client proxy:

// create custom endpoint address in code - based on input in the textbox
EndpointAddress epa = new EndpointAddress(new Uri(textbox.Text));

// instantiate your cilent proxy using that custom endpoint address 
// instead of what is defined in the config file
MyServiceProxy client = new MyServiceProxy("name of endpoint configuration", epa);

Upvotes: 6

Related Questions