Cannot serialize parameter of type 'System.Linq.Enumerable... ' when using WCF, LINQ, JSON
No, one must return a concrete class from a web service. Make the return type List and be done with it.
You have to use the ServiceKnownTypes attribute.
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace Test.Service
{
[ServiceContract(Name = "Service", Namespace = "")]
public interface IService
{
[OperationContract]
[WebInvoke(
Method = "GET",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
[ServiceKnownType(typeof(List<EventData>))]
IEnumerable<EventData> Method(Guid userId);
}
}
Basically you need to know the concrete type of what you're returning. Pretty simple.
You need to pass interoperable collections to and from your WCF methods.
WCF plays best with simple types and arrays.
Pass in an array from your client and then turn it into an IEnumerable in the service.
Stuff like IEnumerable is not interoperable, which is what WCF is trying to be.
There may be a way to get around it with known types, but I always strive to make my components as flexible as possible.