Kontrakty usług

  1. Atrybut ServiceContract zawsze należy stosować dla interfejsu, nie dla klasy:

    // Tego należy unikać:
    [ServiceContract]
    class MyService
    {
       [OperationContract]
       public void MyMethod()
       {...}
    }
    // Tak jest dobrze:
    [ServiceContract]
    interface IMyContract
    {
       [OperationContract]
       void MyMethod();
    }
    class MyService : IMyContract
    {
       public void MyMethod()
       {...}
    }
  2. Nazwę kontraktu usługi należy poprzedzić przedrostkiem I:

    [ServiceContract]
    interface IMyContract
    {...}
  3. Należy unikać operacji przypominających właściwości:

    // Tego należy unikać:
    [ServiceContract]
    interface IMyContract
    {
       [OperationContract]
       string GetName();
       [OperationContract]
       void SetName(string name);
    }
  4. Należy unikać kontraktów obejmujących po jednej składowej.

  5. Każdy kontrakt usługi powinien ...

Get Programowanie usług WCF now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.