使用消息契约的 WCF 序列化枚举
我有一些使用消息合约的网络服务。可能值得一提的是,对于这些服务,我无法转向数据契约...
我的一个类型指定了一个属性,其类型恰好是枚举:
[SerializableAttribute()]
[MessageContract(IsWrapped = false)]
[KnownType(typeof(RiskTypeCode))]
public partial class RiskType : Lookup
{
private RiskTypeCode codeField;
/// <remarks/>
[XmlElement(ElementName="code")]
[MessageBodyMember]
public RiskTypeCode Code
{
get
{
return this.codeField;
}
set
{
this.codeField = value;
}
}
等
我的枚举定义为:
[Serializable()]
[DataContract]
public enum RiskTypeCode
{
/// <remarks/>
[XmlEnumAttribute(Name = "THING1")]
[EnumMember]
THING1,
/// <remarks/>
[XmlEnumAttribute(Name="THING2")]
[EnumMember]
THING2,
/// <remarks/>
[XmlEnumAttribute(Name="THING3")]
[EnumMember]
THING3,
}
但是当我通过网络发送它时, RiskTypeCode 属性未序列化 - 即从输出中省略。
我需要用什么来装饰我的枚举/属性才能使其通过电线?
I have some web services that use Message contracts. It's probably worth mentioning that for these services, I cannot shift to Data contracts...
One of my types specifies a property whose type happens to be an enum:
[SerializableAttribute()]
[MessageContract(IsWrapped = false)]
[KnownType(typeof(RiskTypeCode))]
public partial class RiskType : Lookup
{
private RiskTypeCode codeField;
/// <remarks/>
[XmlElement(ElementName="code")]
[MessageBodyMember]
public RiskTypeCode Code
{
get
{
return this.codeField;
}
set
{
this.codeField = value;
}
}
e.t.c.
My enum is defined as:
[Serializable()]
[DataContract]
public enum RiskTypeCode
{
/// <remarks/>
[XmlEnumAttribute(Name = "THING1")]
[EnumMember]
THING1,
/// <remarks/>
[XmlEnumAttribute(Name="THING2")]
[EnumMember]
THING2,
/// <remarks/>
[XmlEnumAttribute(Name="THING3")]
[EnumMember]
THING3,
}
But when I send this across the wire, the RiskTypeCode property is not serialised - i.e. it's ommitted from the output.
What do I need to decorate my enum/property with to get it across the wire?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用DataContract和EnumMember作为MessageContract。
Using DataContract and EnumMember, for a MessageContract.