比更新客户端配置文件还要简单??
您可能会考虑将客户端配置放在一个单独的文件中,并创建一个供“正常”使用,另一个供“开发机器”使用。
然后在您的 WCF 配置中,使用外部化配置文件:
<system.serviceModel>
<client configSource="client.normal.config" />
</system.serviceModel>
如果您需要切换到“开发机器”使用,请使用
<system.serviceModel>
<client configSource="client.localhost.config" />
</system.serviceModel>
这两个外部化配置文件将如下所示:
[client.normal.config]
<?xml version="1.0" encoding="utf-8" ?>
<client>
<endpoint name="...." address="http://YourServer/Service1" ...... />
<endpoint name="...." address="http://YourServer/Service2" ...... />
....
<endpoint name="...." address="http://YourServer/ServiceX" ...... />
</client>
[client.localhost.config]
<?xml version="1.0" encoding="utf-8" ?>
<client>
<endpoint name="...." address="http://localhost/Service1" ...... />
<endpoint name="...." address="http://localhost/Service2" ...... />
....
<endpoint name="...." address="http://localhost/ServiceX" ...... />
</client>
这样,您创建一次配置文件用于正常使用,一次用于本地主机使用 - 您可以轻松地在两者之间切换基本配置。
这不是 WCF 特定的功能 - 它是 .NET 配置功能。 任何配置节(但不是配置节组)可以外部化到单独的 *.config 文件中。您可以将 WCF 配置的其他部分放入外部配置文件中(但您不能将整个 <system.serviceModel> 节点外部化,因为这是一个配置节组 - 不是配置节)。