How to get a SPListCollection through a sharepoint 2010 web service? Is it possible?

I was trying like this:

using (SPSite osite = new SPSite(siteUrl))
    using (SPWeb oweb = osite.OpenWeb())
        SPListCollection lstCol = osite.OpenWeb().GetListsOfType(SPBaseType.DocumentLibrary);

        return lstCol;

So, is there any alternative way to achieve this?

3 Answers 3


You have to take the information from the SPList entries in the SPListCollection and put them into some serializable class to return from your web service.

The SPListCollection can't be serialized as it contains SPList objects which needs reference to their SPWeb and the unmanaged COM object behind this to get any information, this is also why you can't use a SPList after the corresponding SPWeb has been Disposed (at least not without leaking memory)


Well in lists.asmx, there is the GetListCollection operation, is that what you're looking for?


  • What I'm trying is to create a custom web service that will return SPListCollection object.Actually,I don't want to get the data in xml format.
    – DeathRider
    Commented May 15, 2012 at 15:06
  • Then that probably doesn't help. You might want to rephrase your question a bit. Commented May 15, 2012 at 15:10

SPListCollection is a server side only object and should only be used there.

I would go down the REST path /_vti_bin/ListData.svc (http://msdn.microsoft.com/en-us/library/ff521587.aspx) or take the CSOM path (http://msdn.microsoft.com/en-us/library/ee538683).


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.