Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#WCFDesign
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 21-Feb-13 5:51am

1 solution

Rate this: bad
good
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);
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 756
1 OriginalGriff 452
2 Tadit Dash 350
3 sanket saxena 329
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid