底层连接已关闭:连接意外关闭。 [英] The underlying connection was closed: The connection was closed unexpectedly.

查看:91
本文介绍了底层连接已关闭:连接意外关闭。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注基础连接已关闭:连接意外关闭。用于WCF服务。我试图在谷歌上找到解决方案,大多数链接都说要修改配置。我这样做了,但仍然得到同样的错误





客户项目文件



default.aspx.cs



I am getting following "The underlying connection was closed: The connection was closed unexpectedly." for a WCF service. I tried to find the solution on google, and most of the links said to modify the config. I did so, but still getting the same error


Client project files

default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
       {
           try
           {
               AnnetInterviewQ.IQServiceClient obj = new AnnetInterviewQ.IQServiceClient();


               reptInterviewQ.DataSource = obj.GetInterviewQ(2);
               reptInterviewQ.DataBind();
           }
           catch (Exception ex)
           {
               throw ex;
           }



       }





默认.aspx





default.aspx

<asp:Repeater ID="reptInterviewQ" runat="server" >
           
            <ItemTemplate>
             
               <%#Eval("IQId")%>
            </ItemTemplate>
            <ItemTemplate>
               
                <%#Eval("IQ")%>
            </ItemTemplate>
            <ItemTemplate>
                <asp:Repeater ID="reptInterviewOp" runat="server">
                    <ItemTemplate>
                        <%#Eval("IQOP")%>
                       
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:Repeater> 





web.config





web.config

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IIQService" closeTimeout="00:01:00"

                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"

                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"

                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
      <behaviors>
        <endpointBehaviors>
          <behavior name="debuggingBehaviour">
            <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
          </behavior>
          
        </endpointBehaviors>
        
      </behaviors>
        <client>
            <endpoint address="http://localhost:2431/AnnetInterviewService.svc"

                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IIQService"

                contract="AnnetInterviewQ.IIQService" name="BasicHttpBinding_IIQService" />
        </client>







WCF服务



WCFService.svc






WCF Service

WCFService.svc

public List<t_InterviewQ> GetInterviewQ(int yearsExprience)
       {
           InterViewQDataContext obj = new InterViewQDataContext();


           var objIQList= from l in obj.GetTable<t_InterviewQ>()
                          where l.yearsofExpr==yearsExprience
                          select l;

           return objIQList.ToList<t_InterviewQ>();

       }





WCF服务配置





WCF service config

 <connectionStrings>
   <add name="TestConnectionString" connectionString="Data Source=Myserver;Initial Catalog=Test;Integrated Security=True"
     providerName="System.Data.SqlClient" />
 </connectionStrings>
 <system.web>
   <compilation debug="true" targetFramework="4.0" />
 </system.web>
 <system.serviceModel>
   <behaviors>
     <serviceBehaviors>
       <behavior>
         <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
         <serviceMetadata httpGetEnabled="true"/>
         <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
         <serviceDebug includeExceptionDetailInFaults="true"/>
         <dataContractSerializer maxItemsInObjectGraph="2147483646" />
       </behavior>
     </serviceBehaviors>
   </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
<system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>





IService1 .cs





IService1.cs

[ServiceContract]
   public interface IIQService
   {
       [OperationContract]
       List<t_InterviewQ> GetInterviewQ(int yearsExprience);
   }



任何建议..


Any suggestions..

推荐答案

可能有很多原因对于此错误,最佳解决方法是在客户端和服务器的配置文件中打开WCF日志记录,然后检查日志是否存在确切错误。以下链接将帮助您进行WCF日志记录。



记录和跟踪WCF肥皂消息 [ ^ ]
There can be many reasons for this error, best way to troubleshoot is to turn on WCF logging in your config file for both client and server and then check logs for exact error. Below is the link which will help you on WCF logging.

Logging and Tracing WCF Soap Messages[^]


这篇关于底层连接已关闭:连接意外关闭。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆