views:

557

answers:

1

So I've been using this code to automatically serialize my "User" business object which has been working great.

[WebMethod]
public MyUser GetUserFromCard(string code, string cardNumber)
{
    var repo = new MyRepositry(cinemaCode);
    string parameters = string.Empty;
    parameters = MyRepositry.MakeParameter("CardNumber", cardNumber);

    return repo.FindMember(parameters);
}

which is returning this xml

<MyUser>
  <BirthDate>1982-04-13T00:00:00</BirthDate>
  <Address>market st</Address>
  <Suburb>sydney</Suburb>
  <State>NSW</State>
  <Postcode>2000</Postcode>
  <UserName>test user</UserName>
  <Password>passw0rd</Password>
  <FirstName>test</FirstName>
  <LastName>user</LastName>
  <Email>[email protected]</Email>
  <ReceiveEmail>true</ReceiveEmail>
  <CardNumber>454543523443</CardNumber>
  <Points>10</Points>
  <Rewards>
    <Reward/>
    <Reward/>
  </Rewards>
</MyUser>

My Problem is that the rewards array is returning the correct number of elements but they are empty. Both the MyUser and Reward classes have absolutly no annotations or other methods to perform custom serialization.

Any Ideas?

+1  A: 

Can you show the Reward class? In particular, for use with XmlSerializer it must have a public parameterless constructor, and all* the properties must be public with both getters and setters; so the following would behave like you've described:

public class Reward {
    private readonly string name;
    public Reward(string name) {
        this.name = name;
    }
    public string Name {get {return name;}}
}

but this would work:

public class Reward {
    public string Name {get;set;}
}

*=with some minor caveats.

Marc Gravell
Your right, I was missing the setter for all the properties on my Reward object. Thanks!!
gareth stokes