【发布时间】:2019-08-08 19:30:35
【问题描述】:
我有一个带有“POST”方法的 WCF 服务,该方法接受 XML 并将其转换为对象,问题是只有一些字段正在加载。
对象示例:
[DataMember, XmlElement(IsNullable = false, Type = typeof(String))]
public String ClaimKey
{
get;
set;
}
[DataMember, XmlElement(IsNullable = false, Type = typeof(String))]
public String VehicleRegistrationNo
{
get;
set;
}
输入样本
[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 示例:
<ClaimKey>str1234</ClaimKey>
<VehicleRegistrationNo>str1234</VehicleRegistrationNo>
所以使用上面的示例,只有“VehicleRegistrationNo”正在加载,但 ClaimKey 为空。
XML 和类更大,但它加载了大约 40% 的属性。
【问题讨论】:
-
这没有多大意义。发生了一些你没有意识到的事情。没有看到更多的数据,我无能为力。建议采取一小部分 xml,您可以发布显示正在加载和未加载的标签。格式良好的 xml 只能有一个带有子元素的根元素,而您提供的只是两个没有父元素的子元素。