Dynamically switch WCF Web Service Reference URL path through config file

后端 未结 5 2076
误落风尘
误落风尘 2020-12-01 02:56

How do you dynamically switch WCF Web Service Reference URL path through config file ?

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 03:20

    you can´t chance endpoint url after any calling.

    E.G.

    in that case, you will get answer from NEWURL:

    MyClient client = new MyService.MyClient();
    client.Endpoint.Address = new EndpointAddress("NEWURL"); 
    client.Hello(); //return is hello response from NEWURL
    

    but if you will call any method before changing url, the url will be used from app.config, like next example:

    MyClient client = new MyService.MyClient();
    client.Endpoint.Address = new EndpointAddress("NEWURL"); 
    client.Hello(); //return is hello response from BASEURL
    

提交回复
热议问题