简体   繁体   English

如何将我的程序化WCF配置转换为app.config

[英]How can I translate my programmatic WCF configuration into app.config

I have an self hosted WCF server with hard coded configurations. 我有一台带有硬编码配置的自托管WCF服务器。 the server worked fine until I tried to implement some new configurations functionality (changed ports, added ssl) the new config setting did not work (urrr.... ) and I find it hard to locate where are the problems in my code. 在我尝试实现一些新的配置功能(更改端口,添加ssl)之前,服务器运行良好,新的配置设置不起作用(urrr ....),而且我很难找到代码中的问题所在。

instead of digging inside the code that declares the WCF object, I thought about different approach: 我没有去研究声明WCF对象的代码,而是想到了另一种方法:

Is there any way to dump-to-file those hard coded WCF configuration (the entire ) into app.config like text file after all configurations are loaded? 在加载所有配置后,是否有任何方法可以将那些硬编码的WCF配置(整个)转储到文本文件app.config中,例如文本文件? this will enable me to have a easy global view of the entire settings .. 这将使我能够轻松浏览整个设置的全局视图。

mmm .. .by the way, does anyone know a way that will do the translation to the opposite direction? mmm ..。顺便说一句,有人知道向相反方向移动的方法吗? config to code. 配置为代码。

Any advice will be welcomed! 任何建议都将受到欢迎!

ofer 提供

I don't think you will find an automatic way to dump your c#/vb code somewhere and have your configuration converted to the config file xml schema (and vice-versa), however if you ask my personal opinion, if you don't have a strong reason to hard-code your configuration in your code (even if you do so, I would rethink that), you should move the wcf configuration out from your code. 我认为您不会找到一种自动的方法来将c#/ vb代码转储到某个地方并将您的配置转换为config文件xml模式(反之亦然),但是如果您问我个人的意见,有充分的理由将您的配置硬编码到您的代码中(即使您这样做,我会重新考虑),您应该将wcf配置从代码中移出。 Configuration is not responsibility of the code. 配置不是代码的责任。 It is configuration, meaning that if you need to change the "configuration", you don't need a new build. 它是配置,这意味着如果您需要更改“配置”,则不需要新的版本。

In your code, you should just concentrate in the service consumption logic, leaving the configuration to the back-end engine take care of it. 在您的代码中,您应该只专注于服务使用逻辑,而将配置留给后端引擎来解决。 Remember that sometimes you may need adjust some settings, like service throttling, max/min buffer size, MaxItemsInObjectGraph quota, etc. If hard-coded, means a new deployment. 请记住,有时您可能需要调整一些设置,例如服务限制,最大/最小缓冲区大小,MaxItemsInObjectGraph配额等。如果进行硬编码,则意味着进行新的部署。 If in a config file or other repository, means a simple configuration change. 如果在配置文件或其他存储库中,则意味着简单的配置更改。

If you have all your configuration in a config file, when you move your code from environment to environment (Dev, DIT, QA, UAT, Pre-Prod, Production), you can have different settings between environments, if required (because the port number you used is already in use or is blocked in the firewall). 如果将所有配置都保存在配置文件中,则在将代码从一个环境移到另一个环境(Dev,DIT,QA,UAT,Pre-Prod,Production)时,如果需要,您可以在环境之间进行不同的设置(因为端口您使用的号码已被使用或在防火墙中被阻止)。 The release management team will just configure it properly in the config file. 版本管理团队将只在配置文件中正确配置它。

If you want more control over your service configuration, you could consider creating a factory service for your services, where will get all your configuration from a centralized place (database, xml file, etc), and you will configure your code on-the-fly. 如果您想更好地控制服务配置,可以考虑为服务创建工厂服务,该服务将从集中位置(数据库,xml文件等)获取所有配置,并且您可以在以下位置配置代码:飞。

I hope it helps... 希望对您有帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM