//authenticate to the web services of a SharePoint FBA site
using (AuthenticationSvc.Authentication authSvc = new AuthenticationSvc.Authentication())
{
authSvc.Url = @"http://winsvr2003base:14059/_vti_bin/authentication.asmx";
authSvc.CookieContainer = new System.Net.CookieContainer(); //create a new cookie container
authSvc.AllowAutoRedirect = true;
//set the FBA login information
AuthenticationSvc.LoginResult result = authSvc.Login("triplet", "P@ssw0rd");
//check our loginresult to make sure that we don't have any errors
//if we don't have any errors, then consider us authenticated and we can then call our
//other SharePoint web services by passing in our authentication cookie
if (result.ErrorCode == AuthenticationSvc.LoginErrorCode.NoError)
{
try
{
//now that we're authenticated through FBA try and call the lists web service
using (ListsSvc.Lists listSvc = new SharePointFBAWebSvcTester.ListsSvc.Lists())
{
listSvc.Url = @"http://winsvr2003base:14059/_vti_bin/lists.asmx";
//set our authentication cookie that we got above
listSvc.CookieContainer = authSvc.CookieContainer;
//get the lists from the site
XmlNode listCol = listSvc.GetListCollection();
//dump all the lists in our site
Console.WriteLine(listCol.InnerXml);
}
}
catch (Exception ex)
{
Console.WriteLine("Exception occured while calling lists.asmx" + ex.Message);
}
}
else
Console.WriteLine("Error authentication to web service.");
}