title: WCF transport error
body: <p>I have a WCF service that works when hosted on my local machine but does not work when hosted with IIS on the server.</p>
  
  <p>An unhandled communication exception is thrown</p>
  
  <blockquote>
    <p>. "An error occurred while receiving the HTTP response to {url}. 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."</p>
  </blockquote>
  
  <p>The inner exception is </p>
  
  <blockquote>
    <p>"The underlying connection was closed: An unexpected error occurred on
    receive."</p>
  </blockquote>
  
  <p>I have enabled tracing but to my fault I can't really find anything I can see in there that has helped me. Also, I have seem other threads regarding this issue but nothing has seemed to help.</p>
  
  <p>The server is using https I can't help but think that this is the problem. When I run it locally using http. Everything works correctly. </p>
  
  <p>These calls are retrieving very large amounts of data but I can't help that. </p>
  
  <p>Could anyone please help me with this?</p>
  
  <p>Web.Config</p>
  
  <pre><code>  &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="2147483647"/&gt;    
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;diagnostics&gt;
        &lt;messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"&gt;&lt;/messageLogging&gt;
      &lt;/diagnostics&gt;
      &lt;services&gt;
        &lt;service name="Logistics.Wcf.LogisticsService" behaviorConfiguration="serviceBehavior" &gt;        
          &lt;endpoint address="soap" binding="basicHttpsBinding" contract="Logistics.Wcf.ILogisticsService"&gt;&lt;/endpoint&gt;
          &lt;!--&lt;endpoint address="rest" binding="webHttpBinding" contract="Logistics.Wcf.ILogisticsService" behaviorConfiguration="restBehavior"&gt;&lt;/endpoint&gt;--&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="serviceBehavior"&gt;
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
            &lt;dataContractSerializer maxItemsInObjectGraph="2147483647"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="restBehavior"&gt;
            &lt;webHttp helpEnabled="true"/&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;      
        &lt;basicHttpsBinding&gt;
          &lt;binding name="basicHttpsBinding"
            closeTimeout="00:15:00"
            openTimeout="00:15:00"
            receiveTimeout="00:15:00"
            sendTimeout="00:15:00"
            maxBufferSize="2147483647"
            maxBufferPoolSize="2147483647"
            maxReceivedMessageSize="2147483647"
            &gt;
            &lt;security&gt;
              &lt;transport clientCredentialType="None"&gt;&lt;/transport&gt;
            &lt;/security&gt;
            &lt;readerQuotas maxDepth="2147483647"
              maxStringContentLength="2147483647"
              maxArrayLength="2147483647"
              maxBytesPerRead="2147483647"
              maxNameTableCharCount="2147483647" /&gt;
          &lt;/binding&gt;
        &lt;/basicHttpsBinding&gt;
  
      &lt;/bindings&gt;
      &lt;protocolMapping&gt;
  
        &lt;add binding="basicHttpsBinding" scheme="https"/&gt;
      &lt;/protocolMapping&gt;    
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;
    &lt;/system.serviceModel&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
    &lt;connectionStrings&gt;
      &lt;add name="LogisticsEntities" connectionString="metadata=res://*/LogisticsModel.csdl|res://*/LogisticsModel.ssdl|res://*/LogisticsModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=hertz1105\devl;initial catalog=Logistics;user id=airclic2;password=air123_***;connect timeout=6000;applicationintent=ReadWrite;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;   
    &lt;/connectionStrings&gt;
    &lt;system.diagnostics&gt;
      &lt;sources&gt;
        &lt;source name="System.ServiceModel" switchValue="Information, ActivityTracing"&gt;
          &lt;listeners&gt;
            &lt;add name="log" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Traces.scvlog"&gt;&lt;/add&gt;
          &lt;/listeners&gt;
        &lt;/source&gt;      
      &lt;/sources&gt;
      &lt;trace autoflush="true"&gt;&lt;/trace&gt;
    &lt;/system.diagnostics&gt;
  </code></pre>
  
  <p>Contract:</p>
  
  <pre><code>[OperationContract]
  [WebGet(UriTemplate = "/GetDeliveryInstructions?authenticationToken={AUTHENTICATIONTOKEN}&amp;countryCode={COUNTRYCODE}&amp;beginDate={BEGINDATE}&amp;endDate={ENDDATE}", ResponseFormat = WebMessageFormat.Xml)]
              List&lt;DeliveryInstruction&gt; GetDeliveryInstructions(string authenticationToken, string countryCode, string beginDate, string endDate);
  </code></pre>
  
  <p>Service Method:</p>
  
  <pre><code>public List&lt;DeliveryInstruction&gt; GetDeliveryInstructions(string authenticationToken, string countryCode, string beginDate, string endDate)
          {
              try
              {
                  if (AuthenticationTokenValidator.IsValidToken(authenticationToken))
                      return DeliveryInstructionAdministrator.GetList(countryCode, beginDate, endDate).ToList();
                  else
                      throw new InvalidOperationException("Your token is invalid or expired.");                    
              }
              catch (FaultException&lt;TimeoutException&gt;)
              {
                  return DeliveryInstructionAdministrator.GetList(countryCode, beginDate, endDate).ToList();
              }
              catch (FaultException faultException)
              {
                  WebServiceExceptionLog logEntry = new WebServiceExceptionLog(faultException, "Logistics.Wcf", "GetDeliveryIntructions", faultException.GetType().ToString(), authenticationToken);
                  ExceptionLogger.LogException(logEntry);
                  return null;
              }
              catch (CommunicationException communcationException)
              {
                  WebServiceExceptionLog logEntry = new WebServiceExceptionLog(communcationException, "Logistics.Wcf", "GetDeliveryIntructions", communcationException.GetType().ToString(), authenticationToken);
                  ExceptionLogger.LogException(logEntry);
                  return null;
              }
          }
  </code></pre>
  
  <p><strong>* UPDATE *</strong>
  The problem is with Entity Framework. I am using Entity Framework to retrieve POCO entities. Still not sure how to fix it though. </p>