如何以编程方式修改 WCF app.config 端点地址设置? [英] How to programmatically modify WCF app.config endpoint address setting?

查看:24
本文介绍了如何以编程方式修改 WCF app.config 端点地址设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式修改我的 app.config 文件以设置应使用哪个服务文件端点.在运行时执行此操作的最佳方法是什么?供参考:

I'd like to programmatically modify my app.config file to set which service file endpoint should be used. What is the best way to do this at runtime? For reference:

<endpoint address="http://mydomain/MyService.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IASRService"
    contract="ASRService.IASRService" name="WSHttpBinding_IASRService">
    <identity>
        <dns value="localhost" />
    </identity>
</endpoint>

推荐答案

我认为您想要的是在运行时换出一个版本的配置文件,如果是这样,请创建您的配置文件的副本(也给它相关的.Debug 或 .Release 等扩展名)具有正确的地址(它为您提供调试版本和运行时版本)并创建一个 postbuild 步骤,根据构建类型复制正确的文件.

I think what you want is to swap out at runtime a version of your config file, if so create a copy of your config file (also give it the relevant extension like .Debug or .Release) that has the correct addresses (which gives you a debug version and a runtime version ) and create a postbuild step that copies the correct file depending on the build type.

这是我过去使用过的构建后事件示例,它使用正确的版本(调试/运行时)覆盖输出文件

Here is an example of a postbuild event that I've used in the past which overrides the output file with the correct version (debug/runtime)

copy "$(ProjectDir)ServiceReferences.ClientConfig.$(ConfigurationName)" "$(ProjectDir)ServiceReferences.ClientConfig" /Y

哪里:$(ProjectDir) 是配置文件所在的项目目录$(ConfigurationName) 是活动的配置构建类型

where : $(ProjectDir) is the project directory where the config files are located $(ConfigurationName) is the active configuration build type

有关如何以编程方式执行此操作的详细说明,请参阅 Marc 的回答.

Please see Marc's answer for a detailed explanation on how to do this programmatically.

这篇关于如何以编程方式修改 WCF app.config 端点地址设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆