Operation Contract Request/Response Pattern?

Topics: General Discussion Forum
Nov 4, 2007 at 11:27 PM
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?