0

I'm trying to expose a web service which returns a list of objects from a method in my project. It's an IList and I believe I need to convert it to a List type so it can be serialised for XML but I can't quite figure out how.

Error:

Cannot serialize member NAA.Data.Profile.Application of type System.Collections.Generic.ICollection`1[[NAA.Data.Application, NAA.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.

Web service code:

public class NAAWebService : System.Web.Services.WebService
{
    private NAA.Services.IService.IProfileService _applicationService;       

    public NAAWebService()
    {
        _applicationService = new NAA.Services.Service.ProfileService(); 
    }


    [WebMethod]
    public List<NAA.Data.Application> GetApplicationList(int id)
    {
        return _applicationService.GetApplicationList().ToList();
    }

And the method in my project:

public IList<Application> GetApplicationList()
{
    IQueryable<Application> _applications;
    _applications = from appl
                in _context.Application
                select appl;
    return _applications.ToList<Application>();
}

Any help at all would be much appreciated! Thanks

MBrazier4
  • 45
  • 1
  • 6
  • The error message says, you can't serialize an interface. What is the problem? – Roman Marusyk Mar 10 '18 at 20:32
  • What's `Application`? And why are you doing `ToList()` on a `List`? Please post a [mcve] – Camilo Terevinto Mar 10 '18 at 20:32
  • @Marusyk I'm unsure of how else to display the list of objects? I think I need to convert it to a list but i'm not sure how – MBrazier4 Mar 10 '18 at 20:36
  • @CamiloTerevinto Application is a table within a data entity model. I was trying to use ToList() to convert the IList object to something I could display in XML. Apologies, I'm kind of new to this. – MBrazier4 Mar 10 '18 at 20:39

0 Answers0