How to return a List<object> in WCF

Piero Alberto

I have my WCF service returning data both in XML and JSON format.

One functios has to return a List, because I don't know which class will be used to fill this list.

So, I have my class:

public class WrapHome
{
    public WrapHome() { }

    private string p_TITOLO { get; set; }
    public string TITOLO { get { return p_TITOLO.ToString(); } set { p_TITOLO = value; } }

    private List<object> p_CHART { get; set; }
    public List<object> CHART { get { return p_CHART; } set { p_CHART = value; } }
}

and my WCF declaration:

[OperationContract]
[WebGet(UriTemplate = "datiHome.xml?token={token}&p1={p1}&p2={p2}", ResponseFormat = WebMessageFormat.Xml)]
List<WrapHome> GetDatiHomeXML(string token, string p1, string p2);

The output is correctly set, but, when it has to return it converted in XML (or JSON), it re-calls the method and finally give the err_connection_reset error.

I know the problem is the List, because if I comment it, it works. How can I use my List in my WCF output?

If you need more details, ask me without any problem.

rudolf_franek

You could define

[KnownType(typeof(MyChildObject0))]
...
[KnownType(typeof(MyChildObjectM))]
public class MyBaseObject { ... }

public class MyChildObject0 : MyBaseObject { ... }
...
public class MyChildObjectM : MyBaseObject { ... }

Or you could add the attribute only once and define static method that returns all M+1 types at once.

and modify:

public class WrapHome
{
  ...
  public List<MyBaseObject> CHART { get;set; }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Return List<object> in Csv format as response WCF C#

From Dev

Return different Object (List or error class) from WCF service

From Dev

how to add list of object and return it

From Dev

WCF Web Service: How to return an inherited object that is known on the client

From Dev

WCF return Class with object field

From Dev

WCF REST Return List in Json

From Dev

How to return List of Object from server in GWT

From Dev

How to return object using list c#

From Dev

How to return object using list c#

From Dev

How can I return an object with a list inside of it?

From Dev

How to return DataSet (xsd) in WCF

From Dev

JAXB - How can I return a List of Objects (List<Object>)

From Dev

WCF REST Service - Unable to return list of objects

From Dev

Sending a list within an object to Wcf Service

From Dev

How do I return a single object with an array and a list?

From Dev

How to deduce the return type of a function object from parameters list?

From Dev

How to find and return an object of <derived type> in a list of <base type>?

From Dev

How to return an object from a list from a method to a method?

From Dev

How to return List<Map<String, Object>> using Hibernate

From Dev

How list of object return a Spring Page with Mongo repository?

From Dev

How to return list as JSON object from jsp in ajax?

From Dev

How to return a list of anonymous object in Linq to Sql on joining two tables

From Dev

How to return an object from a list from a method to a method?

From Dev

How to return datatable form wcf rest services?

From Dev

Entity framework - WCF - return JSON how to do this?

From Dev

How to return JSON result by using LINQ in WCF?

From Dev

How to return standard message on exception/fault in WCF

From Dev

How to return datatable form wcf rest services?

From Dev

Return a single object from list

Related Related

  1. 1

    Return List<object> in Csv format as response WCF C#

  2. 2

    Return different Object (List or error class) from WCF service

  3. 3

    how to add list of object and return it

  4. 4

    WCF Web Service: How to return an inherited object that is known on the client

  5. 5

    WCF return Class with object field

  6. 6

    WCF REST Return List in Json

  7. 7

    How to return List of Object from server in GWT

  8. 8

    How to return object using list c#

  9. 9

    How to return object using list c#

  10. 10

    How can I return an object with a list inside of it?

  11. 11

    How to return DataSet (xsd) in WCF

  12. 12

    JAXB - How can I return a List of Objects (List<Object>)

  13. 13

    WCF REST Service - Unable to return list of objects

  14. 14

    Sending a list within an object to Wcf Service

  15. 15

    How do I return a single object with an array and a list?

  16. 16

    How to deduce the return type of a function object from parameters list?

  17. 17

    How to find and return an object of <derived type> in a list of <base type>?

  18. 18

    How to return an object from a list from a method to a method?

  19. 19

    How to return List<Map<String, Object>> using Hibernate

  20. 20

    How list of object return a Spring Page with Mongo repository?

  21. 21

    How to return list as JSON object from jsp in ajax?

  22. 22

    How to return a list of anonymous object in Linq to Sql on joining two tables

  23. 23

    How to return an object from a list from a method to a method?

  24. 24

    How to return datatable form wcf rest services?

  25. 25

    Entity framework - WCF - return JSON how to do this?

  26. 26

    How to return JSON result by using LINQ in WCF?

  27. 27

    How to return standard message on exception/fault in WCF

  28. 28

    How to return datatable form wcf rest services?

  29. 29

    Return a single object from list

HotTag

Archive