问题描述
我想有一个WCF web服务的datacontract枚举。
I want to have an enum in a datacontract of a WCF webservice.
我使用的尝试
[DataContract]
class myclass
{
[DataMember]
public int id {get; set;}
[DataContract]
public enum myenum
{
[EnumMember]
a,
[EnumMember]
b
}
}
但我不能够访问枚举在WCF客户端。请让我知道我做错了。
But I am not able to access enum at the wcf client. Please let me know what I am doing wrong.
推荐答案
要包含在MEX / WSDL,枚举必须是使用图中的某个地方,比如应该有类型的财产某处 myenum
。不是的主动的用于图形类型被忽略。
To be included in the mex/wsdl, the enum needs to be used somewhere in the graph, for example there should be a property somewhere of type myenum
. Types not actively used in the graph are omitted.
还要注意的是,你实际上并不需要注释枚举的所有的 - 他们会工作得很好。如果你想定制他们在电线上如何行动,你只需要在枚举属性。
Note also that you don't actually need to annotate enums at all - they will work just fine. You only need attributes on enums if you want to customize how they act on the wire.
这篇关于我如何使用在datacontract WCF一个枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!