我如何使用在datacontract WCF一个枚举 [英] How can I use a enum in a datacontract WCF

查看:239
本文介绍了我如何使用在datacontract WCF一个枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个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一个枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆