title: "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host
body: <p>I use Visual Studio 2010 and MS SQL Server 2005. I'm new to WCF and I'm trying to learn while developing a small task managing application.</p>
  
  <p>At the moment I have a solution with two console applications inside it
  - the WCF service
  - a client connecting to the WCF service to test out my code</p>
  
  <p>The WCF service connects to a db using LINQ to SQL. 
  I've implemented an OperationContract which inserts something into the db behind the WCF service and it works.
  I've implemented an OperationContract which returns a GUID from the WCF service to the client and that works too.</p>
  
  <p>When I try to retrieve a list of List from the WCF service it fails with the following error:</p>
  
  <ul>
  <li><p>"An error occurred while receiving the HTTP response to localhost:8000/TaskerTest/Service/operations. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server</p></li>
  <li><p>InnerException: The underlying connection was closed: An unexpected error occurred on a receive.</p></li>
  </ul>
  
  <p>My Contracts (the first two work. GetLists is the problem):</p>
  
  <pre><code>[ServiceContract(Namespace = "http://Tasker_Server")]
  public interface IOperations {
      [OperationContract]
      string CreateList(string listName, string text);
      [OperationContract]
      string UpdateList(int idList, string listName, string text);
      [OperationContract]
      List&lt;ToDoList&gt; GetLists();
  }
  </code></pre>
  
  <p>The implementation: </p>
  
  <pre><code>    public List&lt;ToDoList&gt; GetLists() {
          Guid token = OperationContext.Current.IncomingMessageHeaders.GetHeader&lt;Guid&gt;("token", "ns");
          int? userID = CheckCache(token);
  
          if (userID != null) {
              List&lt;ToDoList&gt; lst = DBAccess.GetListsByUserId(userID.Value);
              return lst;
          }
          else
              return null;
      }
  </code></pre>
  
  <p>The DB access code:</p>
  
  <pre><code>     public static List&lt;ToDoList&gt; GetListsByUserId(int idCredential) {
          TaskerModelDataContext tmdc = new TaskerModelDataContext();
          List&lt;ToDoList&gt; lists = tmdc.ToDoLists.Where(entry =&gt; entry.id_Credential == idCredential).ToList&lt;ToDoList&gt;();
          return lists;
  
      }
  </code></pre>
  
  <p>And the client code (the WCF service is added as a Service Reference to the client project):</p>
  
  <pre><code>        TaskerService.LoginClient test2 = new LoginClient();
          string username = "usr1", password = "psw1";
          test2.ClientCredentials.UserName.UserName = username;
          test2.ClientCredentials.UserName.Password = password;
  
          Guid result = Guid.Empty;
          try {
              result = test2.CheckCredentials(username, password);
              Console.WriteLine("Login OK!");
          }
          catch (Exception e) {
              Console.WriteLine(e.Message);
          }
  
          TaskerService.OperationsClient client = new OperationsClient();
          using(OperationContextScope contextScope = new OperationContextScope(client.InnerChannel)) {
  
              Guid testToken = result; Console.WriteLine(testToken.ToString());
              MessageHeader&lt;Guid&gt; mhg = new MessageHeader&lt;Guid&gt;(testToken);
              MessageHeader untyped = mhg.GetUntypedHeader("token", "ns");
              OperationContext.Current.OutgoingMessageHeaders.Add(untyped);
  
              client.GetLists();
          }
          client.Close();
  </code></pre>
  
  <p>The client fails with the above exception on: client.GetLists();</p>
  
  <p>I can provide any additional details as needed by readers.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've turned tracing on with</p>
  
  <pre><code>  &lt;system.diagnostics&gt;
      &lt;trace autoflush="true" /&gt;
      &lt;sources&gt;
        &lt;source name="System.ServiceModel"
                switchValue="Information, ActivityTracing"
                propagateActivity="true"&gt;
          &lt;listeners&gt;
            &lt;add name="sdt"
                type="System.Diagnostics.XmlWriterTraceListener"
                initializeData= "SdrConfigExample.e2e" /&gt;
          &lt;/listeners&gt;
        &lt;/source&gt;
      &lt;/sources&gt;
    &lt;/system.diagnostics&gt;
  </code></pre>
  
  <p>Then I've run Microsoft Service Trace Viewer on the generated log and got the following error:</p>
  
  <p>There was an error while trying to serialize parameter . The InnerException message was 'Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected</p>
  
  <p>I've now added [DataContract] to the "ToDoList" class in my dbml file and now I don't receive an exception. I get the correct number of results in my client BUT the contents of each class seem to be empty.</p>