Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I'm new to WCF, and so I would like to ask for some guidelines in designing a web service client.

The target web service has four different environments - system test, integration test, acceptance test and production. The API is exactly the same for all different environments. The user of my application should be able to select what environment to use. In my VS project I have added a service reference to all four environment WSDL:s.

To the question. Since all environments use the same API but with different endpoints, is there any way I can switch between the endpoints in the actual web service call? I don't want to write four different methods for this(building the soap request is a lot of code...).
//Declare the service envelope
SYS_TEST.ServiceEnvelope serviceEnvelope = new ServiceEnvelope ();
serviceEnvelope.Password = "xxx"
//lots of code filling up the request goes here...
SYS_TEST.CalculateXXClient client = new CalculateXXClient();
//Send the request
client.calculateXX(ref serviceEnvelope);
Posted

1 solution

You should have 1 service reference if the APIs are the same. Just programmatically change the endpoint depending on your chosen environment

var uri = new Uri("Your URL for the environment");
service = new ServiceClient();
service.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900