Name attribute of DataMember in WCF looks like not working

和自甴很熟 提交于 2019-12-24 02:57:13

问题


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;
}

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. 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


回答1:


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;
}


来源:https://stackoverflow.com/questions/47808290/name-attribute-of-datamember-in-wcf-looks-like-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!