title: WCF proxy ProcessGetResponseWebException on HttpChannelRequest WaitForReply
body: <h3>ServiceContract</h3>
  
  <pre><code>[OperationContract]
  List&lt;Campaign&gt; AttainCampaigns();
  </code></pre>
  
  <h3>Works when Instantiating Objects Directly</h3>
  
  <pre><code>public List&lt;Campaign&gt; AttainCampaigns()
  {
      var campaign1 = new Campaign { Id = "x", Name = "namex" };
      var campaign2 = new Campaign { Id = "y", Name = "namey" };
      var campaigns = new List&lt;Campaign&gt; { campaign1, campaign2 };
      return campaigns;
  }
  </code></pre>
  
  <h3>If Equivalent Objects from Entity Framework, Error thrown on Client</h3>
  
  <pre><code>// Different implementation getting the campaign objects from database
  private List&lt;Campaign&gt; RetrieveCampaigns()
  {
      return Global.Repositor.Campaigns.Select(c =&gt; c).ToList();;
  }
  
  public static EntityRepositor Repositor
  {
      get
      {
          if (_entityRepositor == null)
              _entityRepositor = new EntityRepositor();
          return _entityRepositor;
      }
  }
  
  public class EntityRepositor : DbContext
  {
      public DbSet&lt;Campaign&gt; Campaigns { get; set; }
  }
  </code></pre>
  
  <h3>No Errors Evident on Server</h3>
  
  <ul>
  <li>Strangely, when I attach the debugger to the process on the server-side I see no exceptions  - Entity Framework seems to nicely instantiate the objects from the underlying SQL Express database</li>
  <li>I do not even see any First Chance Exceptions in Output</li>
  </ul>
  
  <h3>WCF Test Client Exception after About 15 Seconds, Then Immediately</h3>
  
  <ul>
  <li>First time I invoke <code>AttainCampaigns()</code> the client waits/processes for about 15 seconds and then shows the exception below</li>
  <li>All subsequent invocations show error immediately, even if I remove service and reconnect</li>
  </ul>
  
  <p>_My guess is that the database call itself is fine, but it takes too long, so I need to increase certain timeout values in either the server or client configuration? If that is the correct tree to bark under, which timeouts might they be?</p>
  
  <pre><code>An error occurred while receiving the HTTP response to http://example.com/Service.svc. 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 (possibly due to the service shutting down). See server logs for more details.
  Server stack trace: 
     at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
     at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
     at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
     at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
  Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at IBacker.AttainCampaigns()
     at BackerClient.AttainCampaigns()
  Inner Exception:
  The underlying connection was closed: An unexpected error occurred on a receive.
     at System.Net.HttpWebRequest.GetResponse()
     at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
  Inner Exception:
  Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
     at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
     at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
  Inner Exception:
  An existing connection was forcibly closed by the remote host
     at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
     at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
  </code></pre>
  
  <h3>Server - perSession ServiceContract &amp; Web.config</h3>
  
  <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, 
  ConcurrencyMode = ConcurrencyMode.Single)]
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>  &lt;system.web&gt;
      &lt;compilation targetFramework="4.5" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;     
      &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
          &lt;binding name="wsHttp" allowCookies="true"&gt;
            &lt;security mode="None" /&gt;
          &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
        &lt;service name="MyNameSpace.MyImplementation"&gt;
          &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttp"
            name="wsHttpEp" contract="MyNameSpace.IServiceContract" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
      &lt;directoryBrowse enabled="true" /&gt;
    &lt;/system.webServer&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
    &lt;/entityFramework&gt;
  </code></pre>
  
  <h3>Client - ChannelFactory &amp; App.config</h3>
  
  <pre><code>_channelFactory = new ChannelFactory&lt;T&gt;("wsHttpEp");
  Service = _channelFactory.CreateChannel();
  </code></pre>
  
  <p>&amp; </p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
          &lt;binding name="wsHttp" allowCookies="true"&gt;
            &lt;security mode="None" /&gt;
          &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://example.com/Service.svc" contract="MyNameSpace.IServiceContract"
                  binding="wsHttpBinding" bindingConfiguration="wsHttp" name="wsHttpEp" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>