Derived class serialization for REST operation Automatic Help

Topics: Web Api
Sep 13, 2011 at 11:59 PM

Derived class serialization for REST operation Automatic Help.

We have a weird problem with Automatic Help generation for some derived entities. See example bellow with Identity class inheritance. The whole functionality works fine, the only problem is Help page with recurrent xml generation. For some operation Help cannot be produced. We have a lot of Entities used that pattern and the client implementation. Any solution that can fix this issue without changes class name? Is it DataContractSerialiser Problem?

    public class Item : Identity

   {

       public string Description { set; get; }

       public Identity SubItem { set; get; }

       public Identity ParentItem { set; get; }

   }

 

   public class Identity

   {

       public int Id { set; get; }

       public string Name { set; get; }

       public string Type { set; get; }

   }

 

   [ServiceContract]

   [AspNetCompatibilityRequirements( RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed )]

   [ServiceBehavior( InstanceContextMode = InstanceContextMode.PerCall )]

   public class Service1

   {

       [WebGet( UriTemplate = "{id}/" )]

       public Item Get ( string id )

       {

           return new Item {

               Id = 1,

               Name = "Hello A",

              Description = "Desc",

               ParentItem = new Identity(),

               SubItem = new Identity(),

               Type = "MyType"

           };

       }

 

 

<Item xmlns="http://schemas.datacontract.org/2004/07/WcfRestServiceSample.Common.Entities">

<Id>2147483647</Id>

<Name>String content</Name>

<Type>String content</Type>

<Description>String content</Description>

<!--Valid elements of type: Item-->

<ParentItem i:type="Item" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

   <Id>2147483647</Id>

   <Name>String content</Name>

   <Type>String content</Type>

   <Description>String content</Description>

   <!--Valid elements of type: Item-->

 <ParentItem i:type="Item">

     <Id>2147483647</Id>

     <Name>String content</Name>

     <Type>String content</Type>

     <Description>String content</Description>

     <ParentItem i:nil="true" />

     <!--Valid elements of type: Item-->

     <SubItem i:type="Item">

       <Id>2147483647</Id>

       <Name>String content</Name>

       <Type>String content</Type>

       <Description>String content</Description>

       <ParentItem i:nil="true" />

       <!--Valid elements of type: Item-->

        <SubItem i:type="Item">

         <Id>2147483647</Id>

         <Name>String content</Name>

         <Type>String content</Type>

         <Description>String content</Description>

         <ParentItem i:nil="true" />

         <SubItem i:nil="true" />

       </SubItem>

     </SubItem>

   </ParentItem>

   <!--Valid elements of type: Item-->

   <SubItem i:type="Item">

     <Id>2147483647</Id>

     <Name>String content</Name>

     <Type>String content</Type>

     <Description>String content</Description>

     <!--Valid elements of type: Item-->

     <ParentItem i:type="Item">

       <Id>2147483647</Id>

       <Name>String content</Name>

       <Type>String content</Type>

       <Description>String content</Description>

       <ParentItem i:nil="true" />

       <!--Valid elements of type: Item-->

       <SubItem i:type="Item">

         <Id>2147483647</Id>

         <Name>String content</Name>

         <Type>String content</Type>

         <Description>String content</Description>

          <ParentItem i:nil="true" />

         <SubItem i:nil="true" />

       </SubItem>

     </ParentItem>

     <!--Valid elements of type: Item-->

     <SubItem i:type="Item">

       <Id>2147483647</Id>

       <Name>String content</Name>

       <Type>String content</Type>

       <Description>String content</Description>

       <!--Valid elements of type: Item-->

       <ParentItem i:type="Item">

         <Id>2147483647</Id>

         <Name>String content</Name>

         <Type>String content</Type>

         <Description>String content</Description>

         <ParentItem i:nil="true" />

         <SubItem i:nil="true" />

       </ParentItem>

       <SubItem i:nil="true" />

     </SubItem>

   </SubItem>

</ParentItem>

<!--Valid elements of type: Item-->

<SubItem i:type="Item" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

   <Id>2147483647</Id>

   <Name>String content</Name>

   <Type>String content</Type>

   <Description>String content</Description>

   <!--Valid elements of type: Item-->

   <ParentItem i:type="Item">

     <Id>2147483647</Id>

     <Name>String content</Name>

     <Type>String content</Type>

     <Description>String content</Description>

     <!--Valid elements of type: Item-->

     <ParentItem i:type="Item">

       <Id>2147483647</Id>

       <Name>String content</Name>

       <Type>String content</Type>

       <Description>String content</Description>

       <ParentItem i:nil="true" />

       <!--Valid elements of type: Item-->

       <SubItem i:type="Item">

         <Id>2147483647</Id>

         <Name>String content</Name>

         <Type>String content</Type>

         <Description>String content</Description>

         <ParentItem i:nil="true" />

         <SubItem i:nil="true" />

       </SubItem>

     </ParentItem>

     <!--Valid elements of type: Item-->

     <SubItem i:type="Item">

       <Id>2147483647</Id>

       <Name>String content</Name>

       <Type>String content</Type>

       <Description>String content</Description>

       <!--Valid elements of type: Item-->

       <ParentItem i:type="Item">

         <Id>2147483647</Id>

         <Name>String content</Name>

         <Type>String content</Type>

         <Description>String content</Description>

          <ParentItem i:nil="true" />

         <SubItem i:nil="true" />

       </ParentItem>

       <SubItem i:nil="true" />

     </SubItem>

   </ParentItem>

   <!--Valid elements of type: Item-->

   <SubItem i:type="Item">

     <Id>2147483647</Id>

    <Name>String content</Name>

     <Type>String content</Type>

     <Description>String content</Description>

     <!--Valid elements of type: Item-->

     <ParentItem i:type="Item">

       <Id>2147483647</Id>

       <Name>String content</Name>

        <Type>String content</Type>

       <Description>String content</Description>

       <!--Valid elements of type: Item-->

       <ParentItem i:type="Item">

         <Id>2147483647</Id>

         <Name>String content</Name>

         <Type>String content</Type>

         <Description>String content</Description>

         <ParentItem i:nil="true" />

         <SubItem i:nil="true" />

       </ParentItem>

       <SubItem i:nil="true" />

     </ParentItem>

     <SubItem i:nil="true" />

   </SubItem>

</SubItem>

</Item>