简体   繁体   English

WCF中DataMember的名称属性看起来不起作用

[英]Name attribute of DataMember in WCF looks like not working

I have WCF service exposed to multiple client. 我有WCF服务公开给多个客户端。 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;
}

I have tried to change it to 我试图将其更改为

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

but when looks like data member Name property not working. 但是当看起来像数据成员的Name属性不起作用时。 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. 我尝试了WCF测试客户端,当使用WCF参考时,它显示了诸如OrderId和OrderDetails之类的操作性,而不是我认为的在Name Attribute中声明的那样。 Please help me in correcting it 请帮助我纠正它

I believe you forgot to decorate your class with DataContract . 我相信您忘了用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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM