Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WCF Design
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
0 OriginalGriff 645
1 Maciej Los 225
2 Abhinav S 171
3 Richard Deeming 160
4 Suvendu Shekhar Giri 159
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,135
2 Peter Leow 5,042
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2015
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