Click here to Skip to main content
13,352,408 members (37,398 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 21-Feb-13 6:51am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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);

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100