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

查看:186
本文介绍了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之类的操作性,而不是我认为的在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天全站免登陆