1、总是将ServiceContractAttribute特性应用到接口上,而不是类上
[OperationContract]
public void MyMethod()
{...}
[OperationContract]
void MyMethod();
public void MyMethod()
{...}
[OperationContract]
string GetName();
[OperationContract]
void SetName(string name);
//避免:
[ServiceContract]
class MyService
{
}
//正确:
[ServiceContract]
interface IMyContract
{
}
class MyService:IMyContract
{
}
2、服务契约要添加前缀I:
[ServiceContract]
interface IMyContract
{...}
3、避免准属性(Property-Like)操作
//避免
[ServiceContract]
interface IMyContract
{
}
4、避免定义只有一个成员的契约
5、每个服务契约最好只定义三到五个成员
6、每个服务契约的成员不要超过20个。12个是可能的实际限定