WCF and enum members

When using enum Members in a WCF Service, be sure to include the EnumMember attribute for every enum member:
[DataContract]

public enum States

{

        [EnumMember]

        Unknown = 0,



        [EnumMember]

        Connected = 1,



        [EnumMember]

        Disconnected = 2

}





[DataContract]

public class ClientState

{

    [DataMember]

    public string ClientID { get; set; }



    [DataMember]

    public States State { get; set; }

}

If you forget to set this, you will receive a CommunicationException containing ErrorCode 10054 in its InnerException.
This is caused by a (De)Serialization problem for the enum values which are not known by name in the proxy.

你可能感兴趣的:(enum)