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."
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";

6 comments:

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.

Dan

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.

Best software development in canada April 26, 2022 at 5:05 AM  

best software Development Company in Canada

Imagine the trajectories of Business Goals, Engineering, Design, and Programming dynamically merging to deliver great software. This is the spirit of Trajectus.
Each project is a unique undertaking. heaf"" https://trajectus.com/Best software development company in Canada.
Our goal is to work with our customers to understand your business objectives, engineer a proficient platform, create a beautiful interface, and create clean code. The key to success is ensuring the project's core business needs are met. We’ll work with you to ensure there is a clear understanding of the core business needs.

We approach software challenges with the idea of engineering the best solution, utilizing the best technologies, to solve a business goal. You’ll often find our competitors have assembled talent that corresponds to the preferred language of its leadership or aligns itself with a certain technology stack. We approach each business challenge or partnership as a unique opportunity. As a true engineering company, it’s important to look at all the potential technologies in the market. Trajectus blends good Engineering Principles, a sound Project Management Methodology, and a diverse team of technologists to form solutions to meet the needs of our clients. Our project methodology enables us to leverage a distributed agile software development environment. The Trajectus team is comprised of experienced Architects, Designers, Project Managers, Business Analysts, and experienced Business Development personnel. Our team members possess a diverse set of technology skills and we have an extensive network of specialists. Team members are located throughout the US and our Offshore Delivery center is based in Hyderabad, India. Our methodology enables us to utilize US resources to engage in an in-depth collaborative development process while leveraging skilled resources to minimize distributed risks, bringing affordability to our clients.
We deliver high quality solutions at a fair price while achieving our targeted deadlines. Most importantly, we are going to produce software to meet your goals.