The Juval Löwy’s “Programing WCF Services” book contains a “WCF Coding Standard” appendix with General Design Guidelines for WCF Services.
One of the guidelines is Avoid property-like operations:
//Avoid property-like operations:
[ServiceContract]
interface IMyContract
{
[OperationContract]
string GetName();
[OperationContract]
void SetName(string name);
}
Could anybody explain what’s wrong with having the string GetName(); operation? What if a string value is all I need from an operation?
If a string value is what you need and you will not need anything more then it is absolutely correct. Probably the better example of the anti-pattern is:
And client calling:
This is completely wrong. You should have single operation accepting first and last name.
Generally you should avoid chatty interfaces and reduce number of roundtrips between service and client. So if you know that you will need only name let expose only operation returning the name. But if you know that you will in the same client’s business operation need also email expose the operation which will return name and email.