Thursday, July 24, 2008

Accessing subsites' lists via the MOSS 2007 Lists.asmx web service

I spent a little bit of time trying to figure this one out. I'm playing with the exposed web services that MOSS 2007 provides, trying to figure out how to manipulate lists via this API. My web reference is set to http://company.com/Clients/_vti_bin/Lists.asmx, but I am getting the same response as if the web reference were set to the site root (i.e. http://company.com/_vti_bin/Lists.asmx).

Thanks to user in.the.dark on MSDN forums (http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/80be9abc-f9e0-49b6-8ebc-8f90ddbf27a2/), a workaround is to set the URL programmatically, like so:

using (com.company.Lists lists = new com.company.Lists())
{
lists.Url = "http://company.com/Clients/_vti_bin/Lists.asmx";
XmlNode listColl = lists.GetListCollection();
}

listColl now contains the subsite's lists, rather than the root site's lists.

2 comments:

A Ranting Man said...

Adding this line that sets the URL creates a new error -

Possible SOAP version mismatch: Envelope namespace [url] was unexpected. Expecting [url].

Kiquenet said...

For me, the signature for GetListItems method is

public System.Xml.Linq.XElement GetListItems(string listName, string viewName, System.Xml.Linq.XElement query, System.Xml.Linq.XElement viewFields, string rowLimit, System.Xml.Linq.XElement queryOptions, string webID)

It use XElement, not XmlElement neither XmlNOde.

And I get the same error about it.