WCF Coding Standards

Essentials

1. Place service code in a class library and not in any hosting EXE.

2. Do not provide parameterized constructors to a service class unless it is a singleton that is hosted explicitly.

3. Enable reliability in the relevant bindings.

4. Provide a meaningful namespace for contracts. For outward-facing services, use your company's URL or equivalent URN with a year and month to support versioning;

for example:
[ServiceContract(Namespace = "http://www.idesign.net/2007/08")]
interface IMyContract
{...}

For intranet services, use any meaningful unique name, such as MyApplication;

for example:
[ServiceContract(Namespace = "MyApplication")]
interface IMyContract
{...}

5. With intranet applications on Windows XP and Windows Server 2003, prefer self-hosting to IIS hosting.

6. On Windows Vista, prefer WAS (IIS7) hosting to self-hosting.

7. Use ServiceHost<T>.

8. Enable metadata exchange.

9. Always name all endpoints in the client config file.

10. Do not use SvcUtil or Visual Studio 2005 to generate a config file.

11. Do not duplicate proxy code. If two or more clients use the same contract, factor the proxy to a separate class library.

12. Always close or dispose of the proxy.
Ebook Download
View all
Learn
View all