Blog

The underlying connection was closed: The connection was closed unexpectedly

Posted by Anil Kumar Blogs | WCF with C# Mar 14, 2013
The underlying connection was closed: The connection was closed unexpectedly.

The underlying connection was closed: The connection was closed unexpectedly.

Untitled.png


If you are expecting an return from called method and using WCF service, then one possible cause behind this error could be your object serialization/de-serialization problem. If your service method returns something that is not serialize-able then your proxy channel makes this error.

To avoid this, just check-

1. The return type and make sure it is serializable. You may have to put [Serializable] attribute with your class as below:

 [DataContract(Namespace = "http://codePattern.net/DataTypes/2013/03", Name = "StudentDetail")]

[Serializable]

 public class StudentDetail

   {

     [DataMember(IsRequired=true)]

        public string StudentName { get; set; }

   }

IsRequired=true; tells that the value will be present while serilizing ( its says underline property is a non-nullable value type).


2.  Make sure your enum values are matched with the values stored inside tables. This is the very critical situation because you don't expect it.


comments
COMMENT USING
PREMIUM SPONSORS
Nevron Software is a global leader in component based data visualization technology for a diverse range of Microsoft centric platforms. Nevron Data Visualization components are used by many companies, educational and government organizations around the world.
Nevron Chart
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Nevron Chart