WCF枚举问题:无法";或;枚举值
我使用enum作为标志并希望“或”它,但总是遇到错误: 枚举值“3”对于类型“Common.EventType”无效,无法序列化。如果类型具有DataContractAttribute属性,请确保存在必要的枚举值并用EnumMemberAttribute属性标记 代码: MyContractClient代理=新的MyContractClient(上下文) proxy.Subscribe(EventType.Event1 | EventType.Event2)WCF枚举问题:无法";或;枚举值,wcf,enums,Wcf,Enums,我使用enum作为标志并希望“或”它,但总是遇到错误: 枚举值“3”对于类型“Common.EventType”无效,无法序列化。如果类型具有DataContractAttribute属性,请确保存在必要的枚举值并用EnumMemberAttribute属性标记 代码: MyContractClient代理=新的MyContractClient(上下文) proxy.Subscribe(EventType.Event1 | EventType.Event2) 提前感谢您需要添加[Flags]属性
提前感谢您需要添加[Flags]属性以通过WCF发送标志 当我遇到这个问题时:
... and cannot be serialized. Ensure that the necessary enum values are present
and are marked with EnumMemberAttribute attribute if the type has
DataContractAttribute attribute
我发现我不小心将枚举作为int而不是实际的枚举值通过WCF代理发送
就我而言
bad: request.MyEnum = 1
good: request.MyEnum = MyActualEnum.Number1
添加以对枚举类型使用位操作(&
和|
)。尽管如此,我不确定这是否能纠正给定的错误。。
... and cannot be serialized. Ensure that the necessary enum values are present
and are marked with EnumMemberAttribute attribute if the type has
DataContractAttribute attribute
bad: request.MyEnum = 1
good: request.MyEnum = MyActualEnum.Number1