Click here to Skip to main content
Licence CPOL
First Posted 9 Mar 2008
Views 54,388
Downloads 679
Bookmarked 18 times

Access a Forms Based SharePoint Site's Web Service

By | 9 Mar 2008 | Article
This article describes how to access the Web Services of a Forms baed authenticated SharePoint site.

Introduction

SharePoint site provides built-in Web Services with which we can access the SharePoint Object Model. To access those Web Services, we need to provide credentials to the Web Service. But if the SharePoint site uses Form based authentication, you may get the error: “The request failed with HTTP status 403: Forbidden”. It’s because Form based authentication works in a different way than others. To work this problem out, you need to use another authentication mechanism in SharePoint which is cookie based.

Concept

To get the list of available Web Services, go to IIS and expand the SharePoint web application. Then, under the node _vti_bin:

In a Form based SharePoint site, to invoke a Web Service, the user must be authenticated with the Authentication.asmx Web Service. The Web Service will return the LoginResult object which specifies the authentication status. The Web Service will not generate any exception if the authentication fails; rather the return object LoginResult will contain the login status. If authentication is successful, then the Web Service will put the credential key in the Web Services’ cookie. But to put the credential to the Web Service’s cookie, we need to initialize the cookie container of the Web Service as:

AuthenticationWSObject.CookieContainer = new CookieContainer();

You can get the cookie as follows:

Cookie cookie = cookies[loginResult.CookieName];

If the Web Service is invoked after initializing the cookie container property, the cookie will be filled with the credential token. Now, we can set the cookie in another Web Service’s cookie to access the site.

The process is shown in the following figure:

Picture2.JPG

Using the code

The given example is a desktop application with two web references to the SharePoint Web Services Authnectincation.asmx and Lists.asmx. So, put the two Web Service addresses in the textbox:

Picture3.JPG

Thanks

I faced a problem in accessing a SharePoint site with Forms based authentication. My ex-team lead Moim Hossain helped me to figure out the solution. So I personally thank him. I have taken for granted that someone will face the same problem and they may get help form this article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sohel_Rana

Web Developer

Bangladesh Bangladesh

Member

Sohel Rana is currently working as Software Engineer in a software firm in Dhaka, Bangladesh. He has years of expertise in working with products like SharePoint, Ektron, DotNetNuke. He's main expertise is in the area of SharePoint.
 
He likes to learn new technologies. He likes to listen music in his spare time.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSite in Windows Authentication PinmemberUdayaraju4:02 8 Feb '12  
GeneralMy vote of 5 PinmemberIlka Guigova11:24 13 Jan '12  
Questionsoap webservice refernce PinmemberAmit990920:02 7 Aug '11  
Questionhttps problem Pinmemberfleschgordon3:48 17 Apr '09  
AnswerRe: https problem PinmemberSohel_Rana5:46 17 Apr '09  
GeneralRe: https problem Pinmemberfleschgordon20:10 19 Apr '09  
GeneralRe: https problem Pinmemberfleschgordon3:40 24 Apr '09  
QuestionProblems while authenticating other web services PinmemberMember 30575612:30 4 Jun '08  
AnswerRe: Problems while authenticating other web services PinmemberSohel_Rana17:34 4 Jun '08  
GeneralRe: Problems while authenticating other web services PinmemberMember 305756119:05 4 Jun '08  
Hi Sohel,
Thanks for the reply.
 
I actually was able to make the web service calls to sharepoint Lists web service before I configured the site for FBA.
 
Also I could find the lists.asmx file in the mentioned location and could browse it without ant problem e.g. "http://www.spsite.com:25232/_vti_bin/lists.asmx" is browsable
 
It is only when I configured it for FBA I got the problem (despite of trying with your code which uses cookie based authentication).
 
Any idea what could be wrong?
Cheers
Amit Agrawal
GeneralRe: Problems while authenticating other web services PinmemberSohel_Rana0:42 5 Jun '08  
GeneralRe: Problems while authenticating other web services Pinmembervenukata0:13 11 May '10  
GeneralRe: Problems while authenticating other web services PinmemberSohel_Rana0:26 11 May '10  
GeneralThanks PinmemberPrabs16:47 29 Apr '08  
GeneralGood Job!!! PinmemberMember 437329318:39 11 Apr '08  
GeneralNot able to redirect to login or any specified page Pinmembersonashish16:19 26 Mar '08  
GeneralRe: Not able to redirect to login or any specified page Pinmembersonashish19:22 27 Mar '08  
GeneralRe: Not able to redirect to login or any specified page PinmemberSohel_Rana21:30 30 Mar '08  
GeneralConnection Error PinmemberJohn Dooner6:28 10 Mar '08  
GeneralRe: Connection Error PinmemberSohel_Rana4:54 12 Mar '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 10 Mar 2008
Article Copyright 2008 by Sohel_Rana
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid