views:

117

answers:

1

I have a datacontract as defined below:

[DataContract(Namespace="",Name="community")]
public class Community {

    [DataMember(Name="id")]
    public int Id{get; set;}

    [DataMember(Name="name")]
    public string Name { get; set; }

    [DataMember(Name="description")]
    public string Description { get; set; }
}

and the service contract goes like this:

[OperationContract]
   [WebGet(
                BodyStyle = WebMessageBodyStyle.Bare,
                ResponseFormat = WebMessageFormat.Xml, 
                UriTemplate = "{id}"
 )]
   Community GetCommunity(string id);

When I make a rest call to the host, I get data but only Id and Name properties are populated. The Description property is null! I am creating the channel by inheriting from ClientBase.

Does anybody know why WCF serializes Id and Name but not Description? The Transfer Encoding is set to 'Chunked' on the response from the host and I would like to know if that has anything to do with it ?

+1  A: 

I found out that some of the properties were not getting serialized because the response xml had the elements in a different order. The solution was to explicitly set serialization order on the datacontract. Here is the datacontract after I added order attribute:

 [DataContract(Namespace="",Name="community")]
public class Community 
{
    [DataMember(Name = "name",Order=2)]
    public string Name { get; set; }

    [DataMember(Name="id",Order = 1)]
    public int Id{get; set;}

    [DataMember(Name="description",Order=3)]
    public string Description { get; set; }
}
darthjit