Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
           }



       }


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

XML
<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 Service

WCFService.svc

C#
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 service config

XML
 <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

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

Any suggestions..
Posted
Updated 16-Sep-13 3:12am
v4

1 solution

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[^]
 
Share this answer
 
Comments
Sandesh M Patil 16-Sep-13 10:27am    
System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
MyInterviewQWCFClient.AnnetInterviewQ.IIQService.GetInterviewQ(Int32 yearsExprience)
MyInterviewQWCFClient.AnnetInterviewQ.IQServiceClient.GetInterviewQ(Int32 yearsExprience)
MyInterviewQWCFClient.WebForm1.Page_Load(Object sender, EventArgs e)
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
System.Web.UI.Page.ProcessRequest()
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
System.Web.UI.Page.ProcessRequest(HttpContext context)
ASP.webform1_aspx.ProcessRequest(HttpContext context)
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
System.Web.HttpRuntime.ProcessRequest(HttpWorkerRequest wr)
Microsoft.VisualStudio.WebHost.Request.Process()
Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)


This is the trace log i received
Mahesh Bailwal 17-Sep-13 0:13am    
This seems to be WCF client log. You might have error information in WCF service log please check that also.
Sandesh M Patil 17-Sep-13 6:46am    
Messages.svclog is empty.

However Tracelog.svclog contains following basic error info.

Activity Name Process action 'http://tempuri.org/IIQService/GetInterviewQ'.
Time 2013-09-17 16:14:40.6207
Level Error
Source System.ServiceModel
Process WebDev.WebServer40
Thread 4
Computer SANDESH
Trace Identifier/Code http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx
Mahesh Bailwal 17-Sep-13 8:23am    
did you turned on logging for both service and client?
Sandesh M Patil 17-Sep-13 8:37am    
WCF service method returns the data as i am debugging.

However at client end i am getting error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900