WCF Coding Standards: Part 2

Service Contracts

1. Always apply the ServiceContractAttribute on an interface, not a class:

//Avoid:
[ServiceContract]
class MyService
{
[OperationContract]

public void MyMethod( )
{...}
}

//Correct:
[ServiceContract]
interface IMyContract
{
[OperationContract]
void MyMethod( );
}
class MyService : IMyContract
{
public void MyMethod( )
{...}
}

2. Prefix the service contract name with I:

[ServiceContract]
interface IMyContract
{...}

3. Avoid property-like operations:

//Avoid:
[ServiceContract]
interface IMyContract
{
[OperationContract]
string GetName( );
[OperationContract]
void SetName(string name);
}

4. Avoid contracts with one member.

5. Strive to have three to five members per service contract.

6. Do not have more than 20 members per service contract. Twelve is probably the practical limit.


Ebook Download
View all
Learn
View all