Tuesday, July 05, 2005

Using SharePoint lists.asmx web service

SharePoint (WSS 2.0) provides several web services that gives you access to different parts of the object model and its data, without the need to use the object model directly and without worrying where the data is stored in a farm deployment. Getting started is a bit tricky, but here is a list of articles that will get you started:

In addition, these tools are priceless for helping with CAML and for viewing the real names of columns in the SharePoint list:

The real column names are those you see in the CAML output area of the U2U tool, and you must use these column names in the XML parameters of the web service methods (e.g. 'Name' is really called 'Title'). If you do not get the name right or reference the wrong list, you will get an error like this:

Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was thrown.

<detail> <errorstring xmlns="...">No such field name.
No field was found with that name. Check the name, and try again.</errorstring><errorcode xmlns="...">0x81020014</errorcode</detail>

Note how easily Microsoft has left out an important piece of information: which field name ?

An important detail when programming against the SharePoint web services is to remember to set the .Url property of your web reference to point to the correct WSS team site. The lists.asmx web service is a virtual service and is by SharePoint magic available in all WSS sites, not only in the IIS virtual directory /_vti_bin/. In addition, remember to apply correct credentials for authentication.

Set the .Url like this (avoid getting //_vti_bin/):

_svcList.Url = siteUrl + "/_vti_bin/lists.asmx";
_svcList.Credentials = System.Net.CredentialCache.DefaultCredentials;

The standard SDK documentation of the lists web service is available on MSDN, along with the rest of the WSS web services.

No comments: