Search code examples
c#webservice-client

switch between test and production web service


I've to implement a web service in c#. Now they have a test and production web service. How can I easily switch between them without typing the code twice.

For example

var client;

if(test){
    client = WsTest.Client();
}
else{
    client = WsProd.Client();
}

With kind regards,


Solution

  • You can use this code instead.

    var client;
    #if DEBUG
        client = WsTest.Client();
    #else
        client = WsProd.Client();
    #endif
    

    Assuming that you will run your tests with a debug version and using a release version for you productive code.

    If you don't want to have a WsTest and a WsProd instead I would put all settings in the Web.config. Then you don't have to switch something in your code and configure your webservice via the Web.config. I would prefere this solution because it's more cleaner.