Serializing data with IEnumerable <T> using WebGet

possible duplicate:
It is not possible to serialize a parameter of type "System.Linq.Enumerable ... when using WCF, LINQ, JSON


Hi,

If my method signature looks like this, it works fine.

[WebGet]
MyClass[] WebMethod()

If the sign looks like this:

[WebGet]
IEnumerable<T> WebMethod()

I get the following error: Unable to serialize a parameter of type "XYZT + <WebMethod> d__2c" (for operation "WebMethod", contract "IService"), because it is not the exact type "System.Collections.Generic.IEnumerable`1 [XYZT]" in and is not in the collection of known types. To serialize a parameter, add the type to the collection of known types for the operation using ServiceKnownTypeAttribute.

I tried to add. ServiceKnownType (TypeOf (IEnumerable))

.

​​- 2 2010 , , , ?

+3
2

, #, .

, , .

.

EDIT. - WebMethod

[WebGet]
MyClass[] WebMethod() { return OtherMethod().ToArray(); }
+7

, IEnumerable . , List Array. , , IEnumerable - , IEnumerable. , , IEnumerables.

, DataContractSerializer IEnumerable XML , , IEnumerable .

, .

+1

Source: https://habr.com/ru/post/1729255/


All Articles