The underlying connection was closed: The connection was closed unexpectedly.
Once in a while I have come across this error while creating and testing a new WCF service. And, after hours of searching for remedies, I have finally found it.
First let's start off with some "solutions" that didn't work. While it was necessary for me to increase the limits on the Service and Client side configs, that was not the issue. Nevertheless, for my uses, these were good add-ins:
In my Web.config file I added the following settings, the pertinent data in yellow:
This did not fix the issue and I kept getting the closed connection exception. The issue was discovered when I began looking into the class that was being returned by my web method and its Data Contract and Members.
My class, named ReturnContainer had a GUID, bool and some strings all marked as Data Member. However there was one member of type object. During some of the processing that gets done, an XElement is assigned to this object member. And, apparently WCF does not know how to serialize an XElement. The solution, for good measure, was 2 fold:
- Change object data type to string
- Change all methods that assign to the member to include a .ToString() when necessary