WCF Service Programming Design Specification (3): Service contract, data contract and instance management design specification. This section covers service contracts and data contract design specifications, and service instance management content. Bilingual version, welcome message exchange.
Service Contracts
Service contract
1.Always Apply the ServiceContract attribute on a interface, not a class:
Mark the ServiceContract property on the contract interface, not on the service 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 an I:
Service contract name begins with I
[ServiceContract]
interface IMyContract
{...}