title: WCF Service and Interface - the result is object, even though ServiceKnownType was used
body: <p>I need to convert some objects that are not compatible with Silverlight to models to send over a WCF service. I've tried using the ServiceKnownType, but the result is still object. I am able to cast the object to the Model after I retreive the result, but I don't want to have to do that every time. Here is an example of what I have attempted.</p>
  
  <p>Is this a good approach? Why doesn't WCF return a BikeModel as an object.</p>
  
  <p>Interface</p>
  
  <pre><code>public interface IBike
  {
    string BikeName { get; set;}
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>[DataContract]
  public class BikeModel : IBike
  {
    [DataMember]
    public string BikeName { get; set; }
  }
  </code></pre>
  
  <p>Other Object that can't be used in Silverlight because of MarshalObjectByRef etc in base class</p>
  
  <pre><code>public class Bike : IBike, UnusableBaseClass
  {
  ....
  }
  </code></pre>
  
  <p>IService1</p>
  
  <pre><code>[ServiceContract]
  [ServiceKnownType(typeof(BikeModel))]
  public interface IService1
  {
      [OperationContract]
      IBike GetBike();
  }
  </code></pre>
  
  <p>Service</p>
  
  <pre><code> public class Service1 : IService1
   {
     public IBike GetBike()
     {
       Bike b = BikeManager.GetFirstBikeInTheDataBase();
       return b;
      }
   }
  </code></pre>
  
  <p>MainPage.xaml.cs -</p>
  
  <pre><code>public MainPage()
  {
    InitializeComponent();
    this.Loaded += (s, a) =&gt;
    {
       ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
       client.GetBikeCompleted += (sender, e) =&gt;
       {
          var d = e.Result;
          // this cast works
          BikeModel model = (BikeModel)d;
        };
        client.GetBikeAsync();
  
      };
  }
  </code></pre>