.net - 在 app.config 中管理多个客户端端点配置(IP 地址等)的最佳方法

标签 .net web-services

我们开发一个系统,其中客户端应用程序是 .NET 客户端,使用 Web 服务与服务器进行通信。我们需要能够使用不同的配置选项来部署客户端,例如IP地址等 到目前为止,我们基本上通过在 app.config 中注释/取消注释不同的配置来管理此问题,例如:

<!--<client>
    <endpoint address="https://localhost/services/service1"
        binding="customBinding" bindingConfiguration="ServiceSoapBinding"
        contract="ServiceReference.Service1" name="ServiceImplPort" />
    <endpoint address="https://localhost/services/service2"
        binding="customBinding" bindingConfiguration="ServiceSoapBinding"
        contract="ServiceReference.Service2" name="ServiceImplPort" />
    ...
    ..
</client>-->
<client>
    <endpoint address="https://prod.example.com/services/service1"
        binding="customBinding" bindingConfiguration="ServiceSoapBinding"
        contract="ServiceReference.Service1" name="ServiceImplPort" />
    <endpoint address="https://prod.example.com/services/service2"
        binding="customBinding" bindingConfiguration="ServiceSoapBinding"
        contract="ServiceReference.Service2" name="ServiceImplPort" />
    ...
    ..
</client>

但显然这不是问题的最佳解决方案,随着配置替代方案数量的增加,它变得有点难以管理。非常欢迎任何有关如何改进这一点的建议。

问候,奥拉

最佳答案

幸运的是,这个问题有一个很好的解决方案。下载并安装MSBuild.Community.Tasks

然后查看以下帖子以了解示例用法

http://chris.widdowson.id.au/?p=781

http://grahamrhay.wordpress.com/2012/03/16/multiple-config-transforms-at-build-time/

警告 设置时间超过 5 分钟,并且您将手动编辑 .csproj 文件

这个解决方案确实工作得很好,有任何问题请回来

关于.net - 在 app.config 中管理多个客户端端点配置(IP 地址等)的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931359/

相关文章:

.net - TypeSpec 元数据表中的恶意条目

c# - 如何使用 OpCodes.Calli 在指向 C++ 对象的指针上调用方法

c# - 在对象初始值设定项中的嵌入式集合上使用集合初始值设定项时没有警告

c# - 调用调度程序和执行之间的时间真的很长

java - REST API 架构

c# - 使用可拖动和可调整大小的选择窗口创建自定义图片框

java - ws 消费者服务地址中的动态属性

javascript - 智能解析字符串构建复杂的api调用

c# - 使用 SOAP 数据包调试 Web 服务

c# - 是否可以记录序列化从 Web 服务返回的对象所花费的时间?