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."
Source="System.Web.Services"
Actor=""
Lang=""
Node=""
Role=""
StackTrace:
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";