When working with WCF many times the exception massage doesn’t help us to solve the problem. The above massage is usually a symptom for one of the following problems:
- The return values are bigger than the value which was defined in the config file.
- There is a problem with the endpoint setting
- There is a problem with serialization of the data
I experienced the 3rt problem which was with enums The problem was that the an enum was defined explicitly with values
Public Enum FrequencyEnums
EveryTime = 1
OncePerHour = 2
OncePerDay = 3
OncePerWeek = 4
Never = 5
End Enum
And the private property that was using this enum was defined as follows
Private m_sendFrequencyID As FrequencyEnums
Now because the enum does not have a definition of a default value and because the property is not initialized explicitly and because the enum value for 0 is missing from the enum and because the default value of enum regardless of the specified options is allwayes 0 When I tried to return instance of this class to the client I got this error: The underlying connection was closed: The connection was closed unexpectedly
The solution is one of the following:
- Define 0 value for enums or
- Define a default value for a property from the enum values.
- Assign initial value to the property
My question is how could I have found this error with Microsoft tools and not by trial and error.