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.


COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.