none
Operation Contract Request/Response Pattern? RRS feed

  • Question

  • I'm looking for guidance on how to structure my OperationContract method signatures. Do I encapsulate my DataContract classes in *Request/*Response MessageContract classes, or just pass my DataContract classes themselves as parameters?

    For example, BarRequest/BarResponse are MessageContracts here:

    [ServiceContract]
    interface IFoo
    {
       [OperationContract]
       BarResponse Bar(BarRequest req);
    }


    or, should I just do this:

    [ServiceContract]
    interface IFoo
    {
       [OperationContract]
       void Bar(Xyzzy req); // BarRequest above encapsulates DataContract Xyzzy.
    }


    Clearly, the former pattern requires much more code, espcially if your ServiceContract contains many OperationContracts. That is, for each OperationContract, you will have two MessageContract classes. That's potentially a lot of code to manage. However, adding additional optional properties to the MessageContract does not require the ServiceContract to change (from a WSDL/XSD perspective).

    Is there a best practice in this area?
    Monday, November 5, 2007 12:28 AM

All replies