none
Send list of derived classes from abstract class in WCF - possible? RRS feed

  • Question

  • Hi,

    I was wondering if there was a way to send the following over WCF:

    Classes:

    abstract class ProjectNode
    {....}

    public class ProjectGroup : ProjectNode
    {...}

    class ProjectTask : ProjectNode
    {...}

    I want to send a list of the form List<ProjectNode>, where nodes are of both ProjectGroup or ProjectNode type, is this possible?

    Regards,
    Paul
    Thursday, January 10, 2008 8:39 PM

Answers

  • Hi Paul,

     

    Yes, that's possible. You will need to annoate your service or the operation with the following so your service will know what to deserialize into when they receive ProjectNode's type:

     

    [ServiceKnownType(typeof(ProjectGroup)]

    [ServiceKnownType(typeof(ProjectTask)]

     

     

    Hope this helps.

    Sara

    Thursday, January 10, 2008 8:51 PM

All replies

  • Hi Paul,

     

    Yes, that's possible. You will need to annoate your service or the operation with the following so your service will know what to deserialize into when they receive ProjectNode's type:

     

    [ServiceKnownType(typeof(ProjectGroup)]

    [ServiceKnownType(typeof(ProjectTask)]

     

     

    Hope this helps.

    Sara

    Thursday, January 10, 2008 8:51 PM
  • Excellent, working now with no problems.

    Thanks again,
    Paul
    Friday, January 11, 2008 11:37 AM
  • i'm using php 5.2.5 soapclient to consume the webservices.... however, when i send an object with abstract types, wcf doesn't know which child class to instantiate... can't find any information on this on the web. please help
    Wednesday, May 14, 2008 2:39 PM
  • Well, surprisingly, I do have the same problem, which I tried to solve using the ServiceKnownType attribute, butI keep getting a Cannot create an abstract class. error... any idea ?
    Friday, September 25, 2009 1:45 PM