我使用添加服务引用创建了使用旧 asmx Web 服务(已托管在网络服务器上)的示例 Web 应用程序。当我在 Visual Studio 2012 中运行此应用程序时,它已经创建了端点、basicHttpBinding 等,没有额外的设置,它可以工作。在我发布它并将其托管在 IIS 上之后,它给出了一个错误,如下所示:
现有连接被远程主机强行关闭 说明:当前 Web 请求执行过程中出现未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Net.Sockets.SocketException:现有连接被远程主机强行关闭
源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
堆栈跟踪:
[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& 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
我的 Web 应用程序的 Web.config 文件:
<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="102400" />
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
<system.serviceModel>
<protocolMapping>
<add binding="basicHttpBinding" scheme="Web"/>
</protocolMapping>
<bindings>
<basicHttpBinding>
<binding name="CMAMobileSoap" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://1.1.1.1/capitaws/CMAMobile.asmx"
binding="basicHttpBinding" bindingConfiguration="CMAMobileSoap"
contract="wsCMA.CMAMobileSoap" name="CMAMobileSoap">
<identity>
<dns value="1.1.1.1"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>