优点和WCF配置文件的缺点VS在配置代码 [英] Pros and Cons of wcf config file vs in code config

查看:302
本文介绍了优点和WCF配置文件的缺点VS在配置代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有创造20+终点为各种用途的自托管C#WCF服务。每间代码本身与服务的app.config中一些基本的配置项目,如端口和地址配置。该服务的伟大工程的测试客户端,但一直没有得到广泛的测试。

I have a self hosted C# WCF service which creates 20+ endpoints for various purposes. Each is configured in the code itself with a few basic config items in the app.config of the service such as port and address. The service works great for the tested clients, but has not been widely tested.

我是标准的WCF配置文件的方式有点猜疑,因为我怕最终用户会误事,因而所做的一切代码。

I was a little leary of the standard wcf config file approach because I was afraid the end user would mess things up and hence did everything in code.

这是个好主意,这样做在配置文件中的配置,因为这样最终用户可以定制它以适应他们的需求或者是在代码中的做法足以满足大多数需求?

Is it a better idea to do the configuration in the config file because then the end user could customize it to their needs or is the in code approach sufficient for most needs?

推荐答案

一个WCF的主要好处是连接的细节抽象距离的代码。如果需要更改任何服务的参数,从web.config这样做可以更容易地完成,而无需重新编译。您可能需要更改端口和地址,例如。如果从代码中这样做,你将需要重建,这可能是不切实际的。此外,我不知道为什么最终用户将与web.config中搞乱正常的,除非真的有必要。

One of the main benefits of WCF is the abstraction of the connection details away from the code. If you need to change any of the service parameters, doing so from the web.config can be done more readily, and without recompilation. You may need to change the "port and address," for instance. If you are doing this from within the code, you would need to rebuild, which may be impractical. Further, I'm not sure why the end user would be messing with the web.config normally, unless it's really necessary.

在总之,除非你有一个很好的理由不使用配置文件,你应该为了得到WCF提供了抽象的全部益处使用它们。

In short, unless you have a good reason not to use the config files, you should probably use them in order to get the full benefit of the abstraction that WCF provides.

这篇关于优点和WCF配置文件的缺点VS在配置代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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