The connected connection was closed: the connection unexpectedly closed

When working with WCF many times, exception massage does not help us solve the problem problem. The above massage is usually a symptom for one of the following problems:

  • The return values ​​are greater than the value that was defined in the configuration file.
  • Problem setting endpoint
  • Problem with data serialization

I had a third problem with the enumeration. The problem was that the enumeration was explicitly defined with the values

Public Enum FrequencyEnums EveryTime = 1 OncePerHour = 2 OncePerDay = 3 OncePerWeek = 4 Never = 5 End Enum 

And the private property that used this listing was defined as follows

 Private m_sendFrequencyID As FrequencyEnums 

Now, since the enumeration has no definition of the default value and because the property is not initialized explicitly and because the enumeration value for 0 is not in the enumeration and because the default value for the enumeration, regardless of the options specified, is always 0 When I tried to return an instance of this class to the client, I got this error: The connected connection was closed: the connection was unexpectedly closed

The solution is one of the following:

  • Define a value of 0 for enumerations or
  • Define the default value for the property from the enumeration values.
  • Assign an initial value to a property

My question is: how could I find this error with Microsoft tools, not trial and error?

+4
source share
2 answers

Found this some time ago, trying to resolve the same error message (I had a different problem). Enabling tracing and using svctraceviewer.exe to view the trace log helped me a lot. For more information, see the following URL: Enable WCF Trace Log

+2
source

All Articles