Today while I was coding away on this Java project I'm working on I realized I needed a little .NET love so I decided to bring up .NET Rocks and listen to the Clemens Vasters interview. As you'd expect the focus of the interview was on services. One of the things that was just covered was that Web Services should only accept a single parameter (or message). What this means is that we don't do this:
[WebMethod]
public bool CustomerExists(int customerID) {
// implementation
}
By coding our web service to accept a single integer as a parameter and returning a boolean we have limited our web service, and made it very difficult to expand upon the implementation. Instead of using an integer and a boolean in our implementation we should be using messages that wrap the integer and boolean. Web Services are about messages so don't ignore them when developing your web services just becuase VS.NET makes it possible to ignore that fact. Instead take a message based approach to developing your services. Wrap your web service parameters in "messages" and return the results in a single message.
public class CustomerExistsRequest {
int customerID;
}
public class CustomerExistsResponse {
bool doTheyExist = false;
}
[WebMethod]
public CustomerExistsResponse CustomerExists(CustomerExistsRequest request) {
// implementation
return new CustomerExistsResponse(doTheyExist);
}