2011-02-18 40 views

回答

75

要改变地址(URL)你只是想覆盖配置中的URL到不同的url。假设您有测试服务和实时服务。你可以做到这一点。

client.Endpoint.Address = new EndpointAddress(Server.IsLiveServer() ? 
    @"LiveUrl" : @"TestURl"); 

如果这些URL来自无论你想

0

相信你能做到这一点,看看这里:How to config clients for a wcf service?

这是绝对正常的指向开发到localhost和生产在web.config

+1

我在7个文件中看到了开发URL的引用:reference.svcmap,.xsd,.wsdl,.disco,.svcinfo和web.config。这是配置web.config所有我需要? – 2011-02-18 00:16:21

+0

嗯,你是说你想改变所有这些,重写硬编码的值触摸web.config? – 2011-02-18 00:17:52

4

没有动态切换。每次要使用另一个URL时,都必须创建服务代理(客户端)的新实例,并将EndpointAddress或enpoint配置名称传递给构造函数。

22

只是为了扩大从艾琳的回答: -

MyClient client = new MyService.MyClient(); 
client.Endpoint.Address = new EndpointAddress(new Uri("insert new url here"), 
    client.Endpoint.Address.Identity, client.Endpoint.Address.Headers); 
client.Open(); 

HTH!