首页 > 解决方案 > 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.

标签: c#xmlwcfpost

解决方案


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


推荐阅读