Section C.3. Service Contracts


C.3. 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.




Programming WCF Services
Programming WCF Services
ISBN: 0596526997
EAN: 2147483647
Year: 2004
Pages: 148
Authors: Juval Lowy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net