Proper ServiceStack Serialization

Say I have a common shared dll that exposes an Interface like:

public interface ITask
{
   void Execute();
   int Result { get; }
}

Then lets say I have a ServiceStack WebService has a class that implementes ITask like:

public class MyTask : ITask
{
   private int _res = 0;
   public void Execute()
   {
      _res = 100 + 20;
   }

   public int Result { get { return _res; } }
}

How do I properly serialize/deserialize this class(MyTask) to the client side so that it can properly call ITask.Execute() ?

Firstly I’d strongly recommend against using interfaces and inheritance in DTO’s.

Secondly ServiceStack promotes using Request and Response DTO’s whereas this looks a lot like a WCF-style RPC Service. To learn more about creating message-based Web Services in ServiceStack and how it differs with WCF and Web API, see these earlier StackOverflow answers:

Once you can define a ServiceStack Service they’re easily consumable using ServiceStack’s .NET generic Service Clients which lets you re-use the Server DTO’s which gives you an end-to-end typed API without code-gen.

You can also use Add ServiceStack Reference for an alternative solution for generating typed DTO’s for different languages/platforms from a remote ServiceStack instance.