WCF service: app.config versus attributes or a mixture of both

邮差的信 提交于 2019-11-28 01:27:47

The service name attribute in the config file must be the fully-qualified name of the service class for WCF to pick up the configuration automatically.

It is possible to mix config and code. However, there is no precedence as such. WCF will read the config file when you instantiate the ServiceHost. If you want to set additional properties in code, they will overwrite what's already there.

Best practice is entirely up to you. The purpose of the config file elements is to decouple the service configuration and implementation, which may or may not be a consideration in your deployment.

UPDATE

Attributes on the service class code are a different story. The purpose of some attributes are to let the developer say "I demand config that is consistent with this attribute, or my service won't run as designed". Therefore, although attributes won't actually override config, WCF will check that config is consistent with attributes and refuse to start the service if they are not consistent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!