none
WCF: CommunicationException: The underlying connection was closed: The connection was closed unexpectedly RRS feed

  • Question

  • Hello

    I have in solution Three projects . One is Silverlight, SilverlightWeb & one is Wpf Project.

    In SilverlightWeb project I add Entity Data Model. I also add Wcf Service .

    So it added IService & Service classes.

    In IService Code is

     [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            void DoWork();
    
            [OperationContract]
            List<Order> getOrders();
        }

    Service Class Code is

     
     public class Service1 : IService1
        {
            public void DoWork()
            {
            }
    
            NorthwindEntities dc;
            public List<Order> getOrders()
            {
              dc  = new NorthwindEntities();
              return dc.Orders.ToList();
            }
    
        }

    Now I want to access that service in My Wpf Project.

    I add Service Reference to my Project By right clicking reference > add Service Reference. then add service reference to project.

    in MainWindow.cs file I do following

    public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Service1Client dc = new Service1Client(); dc.Open(); var data= dc.getProducts();

    // above statement can not execute . It is giving me error that

    //WCF: CommunicationException: The underlying connection was closed:

    // The connection was closed unexpectedly } }


    I dont know it is large data problem Or what is  it. I am using northwind data base.

    As I have Newly start working on it I dont know how to solve this issue.

    Can anybody tell me how to solve this issue?

      


    Friday, March 22, 2013 5:27 AM

Answers

  • You need to increase the value of the limiting parameters: maxBufferSize, MaxReceivedMessageSize and maxArrayLength. These values can be set to 8000000 or higher on both service and client configuration.

    Refer this for sample configuration.


    Lingaraj Mishra

    Friday, March 22, 2013 8:39 AM
  • Hi,

    As it indicated in the error message, please try increase maxReceivedMessageSize attribute of the certain <binding> element, increase maxarrayLength, maxStringLength ,etc. in <readerQuotas> settings (under the <binding> elements) for both the service and client.

    To get the actual error message, I would suggest you enable tracing for your service and utilize the SvcTraceViewer.exe tool to analyze the diagnostic traces.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 27, 2013 10:22 AM
    Moderator

All replies

  • This exception is generic and the underlying cause could be for number of reasons like Serlization/Large Data/Service unavailability. I would suggest you to enable Trace on Service and find out the root cause of this exception.  this link will help you to do that.


    Lingaraj Mishra


    Friday, March 22, 2013 6:34 AM
  • Hello

    I had checked it .

    it is giving me following error.



    Following is my Web.config file
    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework"  type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
          </assemblies>
        </compilation>
      </system.web>
      <connectionStrings>
        <add name="NorthwindEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=Northwind;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <entityFramework>
        <defaultConnectionFactory   type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            
            <behavior name="MyService.ServiceImplementation.MyService_Behavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
       
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    </configuration>

    Following is my App.Config Code.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IService1" />
                </basicHttpBinding>
            </bindings>
            <client>
              <endpoint address="http://localhost:2204/Service1.svc" binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                  name="BasicHttpBinding_IService1" >
               
              </endpoint>
              
            </client>
         
        </system.serviceModel>
    </configuration>

    Can you please analyse it & guide me what to do?

    Friday, March 22, 2013 7:00 AM
  • You need to increase the value of the limiting parameters: maxBufferSize, MaxReceivedMessageSize and maxArrayLength. These values can be set to 8000000 or higher on both service and client configuration.

    Refer this for sample configuration.


    Lingaraj Mishra

    Friday, March 22, 2013 8:39 AM
  • can you please analyse my config files & suggest me how to do that? As I had newly start working on Wcf So Not getting much.

    Can you please suggest me about it?

    Friday, March 22, 2013 9:41 AM
  • can you please analyse my config files & suggest me how to do that? As I had newly start working on Wcf So Not getting much.

    Can you please suggest me about it?

    Hello Vipul Langalia

    I have same problem.

    Did you solve it? If You did, can you tell me how?

    Wednesday, March 27, 2013 9:11 AM
  • Hi,

    As it indicated in the error message, please try increase maxReceivedMessageSize attribute of the certain <binding> element, increase maxarrayLength, maxStringLength ,etc. in <readerQuotas> settings (under the <binding> elements) for both the service and client.

    To get the actual error message, I would suggest you enable tracing for your service and utilize the SvcTraceViewer.exe tool to analyze the diagnostic traces.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 27, 2013 10:22 AM
    Moderator
  • Hi,

    As it indicated in the error message, please try increase maxReceivedMessageSize attribute of the certain <binding> element, increase maxarrayLength, maxStringLength ,etc. in <readerQuotas> settings (under the <binding> elements) for both the service and client.

    To get the actual error message, I would suggest you enable tracing for your service and utilize the SvcTraceViewer.exe tool to analyze the diagnostic traces.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Hi, I have similar problem, I opened thread here The underlying connection was closed: The connection was closed unexpectedly can you check it?

    I enable stack trace for me, but I do not understand well in it. If I'll send to you this Log file, can you check it?

    Wednesday, March 27, 2013 12:23 PM