title: WCF Service Library only works when run from Visual Studio
body: <p>I am learning WCF.  I have an ASP.NET MVC2 web app, and I want to send mime-formatted emails from the app so I thought I'd encapsulate the email functionality in a separate WCF project for future reuse etc.  I therefore added a WCF Service Library to the solution, coded the email functionality, added a Service Reference to the web project, and it all works fine when run from within VS.  However, if I access the web app from a browser window (and not via Visual Studio 'F5'), then the WCF service does not work.  I get the following error:</p>
  
  <blockquote>
    <p>Unable to connect to the remote server
    at
    System.Net.HttpWebRequest.GetRequestStream(TransportContext&amp;
    context) at
    System.Net.HttpWebRequest.GetRequestStream()
    at
    System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
    No connection could be made because
    the target machine actively refused it
    127.0.0.1:8732 at System.Net.Sockets.Socket.DoConnect</p>
  </blockquote>
  
  <p>The web.config file in the web app was amended (by WCF) as follows:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;wsHttpBinding&gt;
          &lt;binding name="WSHttpBinding_IEmailService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
            textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"&gt;
            &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
            &lt;reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" /&gt;
            &lt;security mode="Message"&gt;
              &lt;transport clientCredentialType="Windows" proxyCredentialType="None"
                realm="" /&gt;
              &lt;message clientCredentialType="Windows" negotiateServiceCredential="true"
                algorithmSuite="Default" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/wsHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://localhost:8732/Design_Time_Addresses/Email/EmailService/"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEmailService"
          contract="EmailServiceReference.IEmailService" name="WSHttpBinding_IEmailService"&gt;
          &lt;identity&gt;
            &lt;dns value="localhost" /&gt;
          &lt;/identity&gt;
        &lt;/endpoint&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>What do I need to do to get the app+service to work outside of VS2010?  Also, any deployments tips would be greatly appreciated for when I eventually deploy to our servers.</p>
  
  <p>Thanks.</p>
  
  <p><strong>Edit</strong>
  Thanks for all the answers.  Given that I am going to deploy this on the web, should I create a separate web app or web service which then references the service library, and which i would then deploy to an independent web server in due course?</p>