更新配置文件并更新应用程序中的值 [英] Updating config file and updating the values in application
问题描述
我当前正在使用XLinq通过* .exe可执行文件通过* .exe可执行文件在一个相当大的* .exe.config文件中更新一些设置,该操作通过使用XLinq来导航目录并读取/写入值。用这种方式更新的问题是,更改仅在重新启动可执行文件后才生效,但是我希望更改立即生效。
I am currently updating a few settings in a rather large *.exe.config file via the *.exe executable by using XLinq to navigate the directories and read / write the values. The problem with updating this way is that changes only take effect after restarting the executable, but I would like the changes to take effect instantaneously. Is there a way to tell the executable to reload the *.exe.config file after I make the changes?
感谢所有帮助,在此先感谢您!
All help is appreciated and thanks in advance!
app.config的外骨骼
<configuration>
<system.serviceModel>
<!-- stuff... -->
<client>
<!-- this is the section I changed and want to have updated -->
</client>
</system.serviceModel>
</configuration>
编辑:我对这个主题了解甚少的原因之一是我没有创造app.config-它是由别人的代码自动生成的。我必须更改它并使更改在应用程序中生效的原因是,代码的另一部分(我无权访问)调用配置文件以获取其数据,但是如果我不重新加载部分,然后将使用旧设置,在该应用程序中将不起作用。
One of the reasons that I know so little on this subject is that I didn't create the app.config - it's auto-generated by somebody else's code. The reason that I have to change it and have the changes take effect in the application is that another part of the code (which I have no access to) calls on the config file to get its data, but if I don't reload the section then the old settings will be used, which won't work in this application.
EDIT2:如果我不能动态更改此设置,如何更改代码以便可以动态完成?最佳答案会得到赏金...
If I can't change this dynamically, how do I change the code so that it can be done dynamically? Best answer gets the bounty...
推荐答案
var client =
System.ServiceModel.ChannelFactory<ISampleService>(
System.ServiceModel.Channels.Binding binding,
System.ServiceModel.EndpointAddress remoteAddress)
您还可以通过编程方式连接到服务,并直接为WCF提供所需的配置。
you can connect to a service also programmatically, and give the WCF directly the config needed.
使用此功能,您可以不再需要exe中的wcf配置。
with using this, you do not need the wcf config in the exe any more.
https://msdn.microsoft.com/en-us/library/ms576132.aspx
这篇关于更新配置文件并更新应用程序中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!