【发布时间】:2011-06-28 13:06:29
【问题描述】:
我正在学习 WCF。我有一个 ASP.NET MVC2 Web 应用程序,我想从应用程序发送 mime 格式的电子邮件,所以我想我会将电子邮件功能封装在一个单独的 WCF 项目中以供将来重用等。因此我添加了一个 WCF 服务库到解决方案,对电子邮件功能进行编码,向 Web 项目添加服务引用,并且在 VS 中运行时一切正常。但是,如果我从浏览器窗口(而不是通过 Visual Studio 'F5')访问 Web 应用程序,则 WCF 服务将不起作用。我收到以下错误:
无法连接到远程服务器 在 System.Net.HttpWebRequest.GetRequestStream(TransportContext& 上下文)在 System.Net.HttpWebRequest.GetRequestStream() 在 System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream() 无法建立连接,因为 目标机器主动拒绝 127.0.0.1:8732 在 System.Net.Sockets.Socket.DoConnect
Web 应用程序中的 web.config 文件已修改(由 WCF)如下:
<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>
我需要做什么才能让应用程序+服务在 VS2010 之外工作?此外,当我最终部署到我们的服务器时,我们将不胜感激任何部署提示。
谢谢。
编辑 感谢所有的答案。鉴于我要在 Web 上部署它,我是否应该创建一个单独的 Web 应用程序或 Web 服务,然后引用服务库,然后在适当的时候将其部署到独立的 Web 服务器?
【问题讨论】:
标签: c# visual-studio wcf web-applications