In a WCF application we have a servicecontract with attributes:
namespace We.Work {
[ServiceContract(Namespace = \"We\", Name = \"IWork\", SessionMode =
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.