title: DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0
body: <p>I am attempting to retrieve a list of objects from Entity Framework via WCF, but am receiving the following exception:</p>
  
  <p>There was an error while trying to serialize parameter <a href="http://tempuri.org/:GetAllResult" rel="noreferrer">http://tempuri.org/:GetAllResult</a>. The InnerException message was 'Type 'System.Data.Entity.DynamicProxies.TestObject_240F2B681A782799F3A0C3AFBE4A67A7E86083C3CC4A3939573C5410B408ECCE' with data contract name 'TestObject_240F2B681A782799F3A0C3AFBE4A67A7E86083C3CC4A3939573C5410B408ECCE:<a href="http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies" rel="noreferrer">http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies</a>' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.</p>
  
  <p>I have used WCF in the past, but never with Entity Framework. I have all my entities generated via Entity Framework and are annotated with [DataContract] and [DataMember] attributes. I have no Navigation Properties on any of my entities.</p>
  
  <p>The GetAll() method being called is in an abstract service class:</p>
  
  <pre><code>[ServiceContract]
  public interface IService&lt;T&gt;
  {
      [OperationContract]
      List&lt;T&gt; GetAll();
  }
  </code></pre>
  
  <p>And I am using the ChannelFactory to call my implementation:</p>
  
  <pre><code>Binding binding = new NetTcpBinding();
  EndpointAddress endpointAddress = new EndpointAddress("net.tcp://localhost:8081/" + typeof(TestObjectService).Name);
  using (ChannelFactory&lt;ITestObjectService&gt; channel = new ChannelFactory&lt;ITestObjectService&gt;(binding, endpointAddress))
  {
      ITestObjectService testObjectService = channel.CreateChannel();
      testObjects = testObjectService.GetAll();
      channel.Close();
  }
  </code></pre>
  
  <p>I am hosting it as such:</p>
  
  <pre><code>Type type = typeof(TestObjectService);
  ServiceHost host = new ServiceHost(type,
              new Uri("http://localhost:8080/" + type.Name),
              new Uri("net.tcp://localhost:8081/" + type.Name));
  host.Open();
  </code></pre>
  
  <p>When using debugging, it finds the objects from the database, however, it is failing returning the objects.</p>
  
  <p>Any ideas as to where I may be going wrong?</p>