title: Getting an error consuming asmx web service as add service reference
body: <p>I have created sample web application which consumes old asmx web service(which is already hosted on network server) using add service reference. It has created endpoint, basicHttpBinding, etc. when I'm running this application in visual studio 2012 without an extra settings, its working. After I published it and hosted it on IIS, it gives an error as given below :<br/></p>
  
  <p>An existing connection was forcibly closed by the remote host 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host</p>
  
  <p>Source Error: </p>
  
  <blockquote>
    <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  </p>
  </blockquote>
  
  <p>Stack Trace: </p>
  
  <pre><code>[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
     System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6508791
     System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
  
  [IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
     System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +296
     System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) +19
     System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) +251
  
  [WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
     System.Net.HttpWebRequest.GetResponse() +6442392
     System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55
  
  [CommunicationException: An error occurred while receiving the HTTP response to (http://"web service path"). 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.]
     System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10618399
     System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type) +336
     TestEvantekWebApp.wsCMA.CMAMobileSoap.GetQueueInfo(GetQueueInfoRequest request) +0
     TestEvantekWebApp.wsCMA.CMAMobileSoapClient.TestEvantekWebApp.wsCMA.CMAMobileSoap.GetQueueInfo(GetQueueInfoRequest request) in c:\Users\vishwajeet.kulkarni\Documents\Visual Studio 2012\Projects\TestEvantekWebApp\TestEvantekWebApp\Service References\wsCMA\Reference.cs:721
     TestEvantekWebApp.wsCMA.CMAMobileSoapClient.GetQueueInfo(String tenantID, Int32 pax) in c:\Users\vishwajeet.kulkarni\Documents\Visual Studio 2012\Projects\TestEvantekWebApp\TestEvantekWebApp\Service References\wsCMA\Reference.cs:729
     TestEvantekWebApp.TestEvantekPage.Page_Load(Object sender, EventArgs e) in c:\Users\vishwajeet.kulkarni\Documents\Visual Studio 2012\Projects\TestEvantekWebApp\TestEvantekWebApp\TestEvantekPage.aspx.cs:21
     System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
     System.Web.UI.Control.OnLoad(EventArgs e) +92
     System.Web.UI.Control.LoadRecursive() +54
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
  </code></pre>
  
  <p>My Web.config file of web application:<br/></p>
  
  <pre><code>&lt;configuration&gt;
    &lt;configSections&gt;
    &lt;/configSections&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" maxRequestLength="102400" /&gt;    
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;directoryBrowse enabled="true"/&gt;
    &lt;/system.webServer&gt;
    &lt;system.serviceModel&gt;    
      &lt;protocolMapping&gt;
        &lt;add binding="basicHttpBinding" scheme="Web"/&gt;
      &lt;/protocolMapping&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="CMAMobileSoap" closeTimeout="00:01:00"
                       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"&gt;
            &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;          
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://1.1.1.1/capitaws/CMAMobile.asmx"
            binding="basicHttpBinding" bindingConfiguration="CMAMobileSoap"
            contract="wsCMA.CMAMobileSoap" name="CMAMobileSoap"&gt;
          &lt;identity&gt;
            &lt;dns value="1.1.1.1"/&gt;
          &lt;/identity&gt;
        &lt;/endpoint&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>