Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF枚举问题:无法";或;枚举值_Wcf_Enums - Fatal编程技术网

WCF枚举问题:无法";或;枚举值

WCF枚举问题:无法";或;枚举值,wcf,enums,Wcf,Enums,我使用enum作为标志并希望“或”它,但总是遇到错误: 枚举值“3”对于类型“Common.EventType”无效,无法序列化。如果类型具有DataContractAttribute属性,请确保存在必要的枚举值并用EnumMemberAttribute属性标记 代码: MyContractClient代理=新的MyContractClient(上下文) proxy.Subscribe(EventType.Event1 | EventType.Event2) 提前感谢您需要添加[Flags]属性

我使用enum作为标志并希望“或”它,但总是遇到错误:

枚举值“3”对于类型“Common.EventType”无效,无法序列化。如果类型具有DataContractAttribute属性,请确保存在必要的枚举值并用EnumMemberAttribute属性标记

代码:

MyContractClient代理=新的MyContractClient(上下文)

proxy.Subscribe(EventType.Event1 | EventType.Event2


提前感谢

您需要添加[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