WCF Datacontract,部分字段不反序列化 [英] WCF Datacontract, some fields do not deserialize

查看:25
本文介绍了WCF Datacontract,部分字段不反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我将 WCF 服务设置为来自外部系统的调用的端点.该调用正在发送纯 xml.我正在通过使用 RequestBuilder 从 Fiddler 向服务发送调用来测试系统.

I have a WCF service setup to be an endpoint for a call from an external system. The call is sending plain xml. I am testing the system by sending calls into the service from Fiddler using the RequestBuilder.

问题是我的所有字段都被反序列化,除了两个字段.price_retailprice_wholesale.

The issue is that all of my fields are being deserialized with the exception of two fields. price_retail and price_wholesale.

我错过了什么?所有其他字段反序列化都没有问题 - 服务响应.只是这些领域.

What am I missing? All of the other fields deserialize without an issue - the service responds. It is just these fields.

XML 消息:

<widget_conclusion>
    <list_criteria_id>123</list_criteria_id>
    <list_type>consumer</list_type>
    <qty>500</qty>
    <price_retail>50.00</price_retail>
    <price_wholesale>40.00</price_wholesale>
    <session_id>123456789</session_id>
</widget_conclusion>

服务方式:

public string WidgetConclusion(ConclusionMessage message)
{
    var priceRetail = message.PriceRetail;
}

消息类:

[DataContract(Name = "widget_conclusion", Namespace = "")]
public class ConclusionMessage  
{
    [DataMember(Name = "list_criteria_id")]
    public int CriteriaId  { get; set;}
    [DataMember(Name = "list_type")]
    public string ListType { get; set; }
    [DataMember(Name = "qty")]
    public int ListQuantity { get; set; }
    [DataMember(Name = "price_retail")]
    public decimal PriceRetail { get; set; }
    [DataMember(Name = "price_wholesale")]
    public decimal PriceWholesale { get; set; }
    [DataMember(Name = "session_id")]
    public string SessionId { get; set; }
}

推荐答案

字段在您的消息中的顺序错误.DataContracts 默认按字母顺序排列,不是 声明顺序;并期望 XML 元素按该顺序到达;乱序元素通常会被丢弃.

Fields are in the wrong order for your message. DataContracts default to Alphabetical ordering and not order of declaration; and expects XML elements to arrive in that order; Out of order elements are discarded usually.

修复您的合同​​以明确指定正确的顺序(使用 DataMemberAttribute 的 Order 属性)或确保您的客户以正确的顺序发送它们.

Either fix your contract to specify the right order explicitly (using the Order property of the DataMemberAttribute) or make sure your client sends them in the right one.

这篇关于WCF Datacontract,部分字段不反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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