c# - WCF XML Post Request Only Partially Loading Object
问题描述
I have a WCF Service with a "POST" method that takes in XML and turns it into an object, the problem is only some of the fields are being loaded.
Object Sample:
[DataMember, XmlElement(IsNullable = false, Type = typeof(String))]
public String ClaimKey
{
get;
set;
}
[DataMember, XmlElement(IsNullable = false, Type = typeof(String))]
public String VehicleRegistrationNo
{
get;
set;
}
Input Sample
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
public SalvageInstructionResponse Test(SalvageInstructionRequestHeader Item)
{
this._objOutput = new SalvageInstructionResponse(SalvageInstructionResponseStatus.FAILURE, "Test", Item.ToString());
return this._objOutput;
}
XML Sample:
<ClaimKey>str1234</ClaimKey>
<VehicleRegistrationNo>str1234</VehicleRegistrationNo>
So using the above sample only "VehicleRegistrationNo" is loading but the ClaimKey is null.
The XML and the class are bigger but it's loading about 40% of the properties.
解决方案
To anyone else who gets stuck on this, it's because the nodes in the XML weren't in alphabetical order and no DataMember(OrderNo) wasn't set. So when it was serializing the object .NET was just doing "The best it could".
推荐阅读
- matlab - Matlab:如何将块组合回原始矩阵?
- html - IE 中未显示锚标记
- r - 如何将演示者模式添加到 ioslides
- javascript - 如果只有一个条件为真,是否有一个逻辑运算符返回真?
- c - LLDB 无法读取 argv 指针数组中的内存地址,作为 C 中 main 方法中的参数给出
- javascript - 计算两个保存输入数据的变量并将其输出
- node.js - 类型“{}”缺少“用户”类型的以下属性:lastName、firstName、nickName、img 和另外 6 个
- java-8 - Java8 Streams:从地图值的对象中删除字段
- python - 如何在单个 CSV 文件中保存多个列表?
- android - Exoplayer Leanback 的 Netflix 风格下一集