WCF 中 DataMember 的名称属性看起来不起作用 [英] Name attribute of DataMember in WCF looks like not working

查看:35
本文介绍了WCF 中 DataMember 的名称属性看起来不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 WCF 服务暴露给多个客户端.在某些客户端数据成员名称中,大小写不正确.根据

I have WCF service exposed to multiple client. In some of client datamember name casing was not proper. My Class properties have invalid property name as per casing standards like

public class TransactionParamter
{
    [DataMember]
    public string orderId;
    [DataMember]
    public string orderDetails;
    [DataMember]
    public double orderSumTotal;
}

我已经尝试将其更改为

public class TransactionParamter
{
    [DataMember(Name= "orderId")]
    public string OrderId;
    [DataMember(Name= "orderDetails")]
    public string OrderDetails;
    [DataMember(Name= "orderSumTotal")]
    public double OrderSumTotal;
}

但是当看起来数据成员 Name 属性不起作用时.我已经尝试过 WCF 测试客户端,当采用 WCF 参考时,它显示了像 OrderId 和 OrderDetails 这样的 peroperty,而不是我在 Name Attribute 中声明的那个.请帮我改正

but when looks like data member Name property not working. I have tried WCF test client and when taking WCF reference it shows peroperty like OrderId and OrderDetails instead of what i thought of the one i declare in Name Attribute. Please help me in correcting it

推荐答案

我相信你忘了用 DataContract 装饰你的类.您需要它才能使自定义数据成员名称起作用.

I believe you forgot to decorate your class with DataContract. You need that in order to make custom data member name to work.

[DataContract(Name="transactionParamter")]
public class TransactionParamter
    {
        [DataMember(Name= "orderId")]
        public string OrderId;
        [DataMember(Name= "orderDetails")]
        public string OrderDetails;
        [DataMember(Name= "orderSumTotal")]
        public double OrderSumTotal;
}

这篇关于WCF 中 DataMember 的名称属性看起来不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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