views:

30

answers:

1

I have a WCF REST Starter Kit service. The type handled by the service is a subclass of a base class. For POST requests, the base class members are not correctly populated.

The class hierarchy looks like this:

[DataContract]
public class BaseTreeItem 
{
    [DataMember]
    public String Id { get; set; }
    [DataMember]
    public String Description { get; set; }
}

[DataContract]
public class Discipline : BaseTreeItem
{
    ...
}

The service definition looks like:

[WebHelp(Comment = "Retrieve a Discipline")]
[WebGet(UriTemplate = "discipline?id={id}")]
[OperationContract]
public Discipline getDiscipline(String id)
{
    ...
}

[WebHelp(Comment = "Create/Update/Delete a Discipline")]
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "discipline")]
public WCF_Result DisciplineMaintenance(Discipline discipline)
{
    ...
}

Problem: While the GET works fine (returns the base class Id and Description), the POST does not populate Id and Description even though the XML contains the fields.

Sample XML:

<?xml version="1.0" encoding="utf-8"?>
<Discipline xmlns="http://schemas.datacontract.org/2004/07/xxx.yyy.zzz"&gt;
  <DeleteFlag>7</DeleteFlag>
  <Description>2</Description>
  <Id>5</Id>
  <DisciplineName>1</DisciplineName>
  <DisciplineOwnerId>4</DisciplineOwnerId>
  <DisciplineOwnerLoginName>3</DisciplineOwnerLoginName>
</Discipline>

Thanks for any assistance.

A: 

I could not solve the problem using a DataContractSerializer. I switched to using the XMLSerializerFormat and everything worked fine. In fact, the capabilities of the XMLSerializer are so much better that for purely XML work, it is probably better to use the XMLSerializer in all cases.

HJG