1

I'm trying to build a simple web service which return a list of shows from a database. The web service has the following code to get its data:

private BLLoptredens BLLoptredens = new BLLoptredens();

[WebMethod]
public Array getVoorstellingenByArtiest(string p_artiest)
{
    return BLLoptredens.selectByArtistName(p_artiest).ToArray() ;
}

The data comes from the BLL, which just passes data from the DAL like so:

public IList<Optreden> selectByArtistName(string p_artiest)
{
   var query = (from o in dc.Optredens
                where o.artiest.Contains(p_artiest)
                select o);
   return query.ToList();
}

This crashes with the following error:

You must implement a default accessor on System.Array because it inherits from ICollection

Can something help me on my way with this?

3
  • do not return an Array from the webmethod.you can return an array like Optreden[] if Optreden is serializable instead. Commented Nov 24, 2011 at 13:28
  • I get an iList<Optreden> from my DAL. How can I convert that to Optreden[]? Commented Nov 24, 2011 at 13:29
  • I think the ToArray can do the job, instead of the ToList Commented Nov 24, 2011 at 13:39

3 Answers 3

1

Is there any particular need to give back an interface instead of a full-fledged generic class?

Try changingIList<Optreden> to List<Optreden> -- that should do it.

Sign up to request clarification or add additional context in comments.

2 Comments

that works! Thanks a lot. Is there a reason why I should still use iList instead of List in my code? Otherwise List seems like a more flexible solution?
List<> gives you the full class, where IList<> allows you to give back something that is basically not a List<>, but implements a similar behavior. Since you have a LIst<> already in your method there is no advantage of giving back just an interface.
0

try public List instead of public IList

Comments

0
public Optreden[] getVoorstellingenByArtiest(string p_artiest)
{
    return BLLoptredens.selectByArtistName(p_artiest).ToArray() ;
}

Note the Optreden[]. And I hope the Optreden is a DataContract with serializable members decorated with DataMember attribute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.