Skip to Main Content
Programming WCF Services
book

Programming WCF Services

by Juval Lowy
February 2007
Intermediate to advanced content levelIntermediate to advanced
634 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services

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]
    interfaceIMyContract
    {...}
  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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services, 3rd Edition

Programming WCF Services, 3rd Edition

Juval Lowy
Mastering ASP.NET Web API

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Publisher Resources

ISBN: 0596526997Supplemental ContentErrata Page