Friday, June 13, 2008

Error While trying to access Sharepoint List in subsite using Lists Webservice ?

I wanted to access the data from SharePoint List present on remote server in an utility. As the site was pesent on remote server, I used Lists WebService to access the data.

I added the WebReference as : http://mainsite/subsite/_vti_bin/Lists.asmx
and tried to run the code only to be hit with a Soap Exception.

Following are the error details I got :
System.Web.Services.Protocols.SoapException was unhandled by user code
Message="Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at ProdLists.Lists.GetListItems(String listName, String viewName, XmlNode query, XmlNode viewFields, String rowLimit, XmlNode queryOptions, String webID) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\utility\f0b09a93\a4ef1a67\App_WebReferences.3-c5ghn5.2.cs:line 496
at _Default.Page_Load(Object sender, EventArgs e) in d:\Projects\Utility\Default.aspx.cs:line 45
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Was unable to find the reason for this bahavior, however figured out that eventhough the reference was added to the WebService under subsite, it bydeault points to the Lists under mainsite or the top level site.

To tackle this I had to set the URL property expicitly at runtime.

Following are the lines you will have to add to be able to access the lists under any subsite :

ProdLists.Lists prodService = new ProdLists.Lists();
prodService.UseDefaultCredentials = true;
prodService.Url = "http://mainsite/subsite/_vti_bin/Lists.asmx";


Dan Meineck October 22, 2008 at 2:01 AM  

Thanks Laxmikant. I was getting the problem where even though the Subsite URI was specified, GetListCollection() returned only the lists from the root site.

I'll implement your suggestion. Strange why Microsoft decided to implement it like this?

Thanks for posting.


Marlo June 18, 2009 at 6:35 AM  


Anonymous June 26, 2009 at 1:18 PM  

Wow, thank you so much!!! I've been looking for this solution for DAYS!

Anonymous July 7, 2010 at 5:36 AM  

I specified the Webservice with the following URL "http://server/site/subsite/_vti_bin/service.asmx"

But while debugging you will see that the call will go to "http://server/_vti_bin/service.asmx" of what ever reason.

THANKS soooo much for the solution !

Fabian Carter June 15, 2012 at 5:30 AM  

I have even faced many such problems while accessing to SharePoint with different procedures and functions. Sometimes the error is quite small but we are not able to understand where exactly it lies.