Click here to Skip to main content
15,880,503 members
Articles / Programming Languages / C#

Access a Forms Based SharePoint Site's Web Service

Rate me:
Please Sign up or sign in to vote.
4.60/5 (12 votes)
9 Mar 2008CPOL2 min read 111.9K   2.2K   21   21
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:

Image 1

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:

C#
AuthenticationWSObject.CookieContainer = new CookieContainer();

You can get the cookie as follows:

C#
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)


Written By
Architect ImpleVista Aps
Denmark Denmark
Sohel has more than six years of experience in professional software development with extensive involvement in Web based Object-Oriented, Multi-Tiered application design and development. He's Familiar with Test Driven Development (TDD) and refactoring techniques as well as having expertise in architecturing large enterprise applications. He has Experience in working with Content Management System and Portal Management System tools like SharePoint, DotNetNuke, Ektron.

Over last few years, he’s involved in development with projects on Microsoft SharePoint and received Microsoft MVP for SharePoint Server Development in the year 2011 and 2012. Currently he's working in a software company located Copenhagen,Denmark on a project integrating SharePoint and SAP. You can read his popular blog at: http://ranaictiu-technicalblog.blogspot.com

Comments and Discussions

 
QuestionSite in Windows Authentication Pin
Udayaraju8-Feb-12 4:02
Udayaraju8-Feb-12 4:02 
GeneralMy vote of 5 Pin
Ilka Guigova13-Jan-12 11:24
Ilka Guigova13-Jan-12 11:24 
Questionsoap webservice refernce Pin
Amit99097-Aug-11 20:02
Amit99097-Aug-11 20:02 
AnswerRe: soap webservice refernce Pin
dxs75315-Apr-14 23:23
dxs75315-Apr-14 23:23 
Questionhttps problem Pin
fleschgordon17-Apr-09 3:48
fleschgordon17-Apr-09 3:48 
AnswerRe: https problem Pin
Sohel_Rana17-Apr-09 5:46
Sohel_Rana17-Apr-09 5:46 
GeneralRe: https problem Pin
fleschgordon19-Apr-09 20:10
fleschgordon19-Apr-09 20:10 
GeneralRe: https problem Pin
fleschgordon24-Apr-09 3:40
fleschgordon24-Apr-09 3:40 
QuestionProblems while authenticating other web services Pin
Member 30575614-Jun-08 2:30
Member 30575614-Jun-08 2:30 
AnswerRe: Problems while authenticating other web services Pin
Sohel_Rana4-Jun-08 17:34
Sohel_Rana4-Jun-08 17:34 
GeneralRe: Problems while authenticating other web services Pin
Member 30575614-Jun-08 19:05
Member 30575614-Jun-08 19:05 
GeneralRe: Problems while authenticating other web services Pin
Sohel_Rana5-Jun-08 0:42
Sohel_Rana5-Jun-08 0:42 
GeneralRe: Problems while authenticating other web services Pin
venukata11-May-10 0:13
venukata11-May-10 0:13 
GeneralRe: Problems while authenticating other web services Pin
Sohel_Rana11-May-10 0:26
Sohel_Rana11-May-10 0:26 
GeneralThanks Pin
Prabs29-Apr-08 16:47
Prabs29-Apr-08 16:47 
GeneralGood Job!!! Pin
Karl KO11-Apr-08 18:39
Karl KO11-Apr-08 18:39 
GeneralNot able to redirect to login or any specified page Pin
sonashish26-Mar-08 16:19
sonashish26-Mar-08 16:19 
GeneralRe: Not able to redirect to login or any specified page Pin
sonashish27-Mar-08 19:22
sonashish27-Mar-08 19:22 
GeneralRe: Not able to redirect to login or any specified page Pin
Sohel_Rana30-Mar-08 21:30
Sohel_Rana30-Mar-08 21:30 
GeneralConnection Error Pin
John Dooner10-Mar-08 6:28
John Dooner10-Mar-08 6:28 
GeneralRe: Connection Error Pin
Sohel_Rana12-Mar-08 4:54
Sohel_Rana12-Mar-08 4:54 

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

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