Search code examples
wcfmobilesoadatacontract

strategy for WCF Mobile contract


Is there a clever way to structure my WCF service, such that I can implement a service once and have it return different data contracts for different callers? (i.e. mobile clients)

We have already developed a set of services which are consumed by a desktop application and are now building a mobile version of the application. The problem is that the data transfer objects (DTOs) returned are too big and contain unnecessary members for the mobile application. With it going over a mobile network we would like to cut these out to improve performance, however the implementation of the services will be identical.

Ideas we have so far:

  • Setting EmitDefault to false and then not mapping all properties on the DTO for mobile callers (we are using automapper so may be able to do something with multiple mapping configurations)
  • Inherited DTO types for desktop that extend the basic mobile type using the KnownType attribute.
  • Just building a separate service entirely, but making sure all logic is in a shared business service layer (which it should be already)

Does anyone know if there is any guidance out there for this requirement?


Solution

  • Personally I would keep the implementations separate. As you point out, each set of clients - mobile and desktop - have different requirements. You can share the contracts for your service, just have different implementations / services. This will allow to specialise the services for each client, and makes it easier to extend, modify and test.