title: How To Use Interface as DataContract in WCF
body: <p>I need invoke webservice operations using standard wsdl, but data objects must be different in client and in the server.</p>
  
  <p>Using interfaces for data objects in a common library, making proxy classes for it in client and in server.</p>
  
  <p>Then, I'm declaring operation contract using the interface, but WCF don't recognize it.</p>
  
  <p>I yet tried use DataContractSerializerBehavior and set knownTypes, no success yet.</p>
  
  <p>Someone can help-me? I've attached a complete solution with more details.</p>
  
  <pre><code>public interface Thing
  {
     Guid Id {get;set;}
     String name {get;set;}
     Thing anotherThing {get;set;}
  }
  
  [DataContract]
  public class ThingAtServer: BsonDocument, Thing // MongoDB persistence
  { 
     [DataMember]
     Guid Id {get;set;}
     //... 
  }
  
  [DataContract]
  public class ThingAtClient: Thing, INotifyPropertyChanged // WPF bindings
  { 
     [DataMember]
     Guid Id {get;set;}
     //... 
  }
  
  [ServiceContract]
  public interface MyService
  {
    [OperationContract]
    Thing doSomething(Thing input);
  }
  </code></pre>
  
  <p><strong>Click here do see a <a href="https://github.com/josefernandotolentino/InterfaceDataContract" rel="nofollow">Sample project on GitHub</a> with TestCases</strong></p>