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:
Unable to connect to the remote server
at
System.Net.HttpWebRequest.GetRequestStream(TransportContext&
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
The web.config file in the web app was amended (by WCF) as follows:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<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">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/Design_Time_Addresses/Email/EmailService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEmailService"
contract="EmailServiceReference.IEmailService" name="WSHttpBinding_IEmailService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
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.
Thanks.
Edit
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?
The reason is when u run with F5 your wcf service get automatically hosted WcfSvcHost.exe . But when directly access the web page thru localhost (without havign wcf service hosted) you get this error. What you need to do is host the wcf first in IIS ( or anywhere else) and then use the web app.
Here are options for hosting your wcf service.