WCF and Enums : The underlying connection was closed: The connection was closed unexpectedly
I was getting the error "The underlying connection was closed: The connection was closed unexpectedly" when retrieving an array of a complex class.
It turns out that one of the enums in the class was not declared properly and this was causing this ambiguous error.
Thanks to Merrick Chaffer for his article that told me what my I was missing.
The service needs the enum type to be registerd as a service known type:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceKnownType(typeof(SuitType))]
public class PokerService
{
and the Enum needs each value used to have an [EnumMember] attribute:
public enum SuitType
{
[EnumMember]
Unknown = 0,
[EnumMember]
Club = 1,
[EnumMember]
Spade = 2,
[EnumMember]
Diamond = 3,
[EnumMember]
Heart = 4,
}