If you want to connect to SharePoint site which uses FBA authentication, you can use following function which will return cookie to you. You need to pass NetworkCredentials inside this method where you need to specify username, password and domain(if no domain than pass string.empty).
Whenever you create any instance for Lists webservice, you need to create cookie container for lists.
Lists.CookieContainer = new CookieContainer();
than you can call below function which will return you cookie name and you need to add this cookie to Lists.
Lists.CookieContainer.Add(AuthenticatedCookie);
Than you can try to execute any method for Lists webservice.
private Cookie AuthenticateFBASite(string AuthenticationSiteURL, string UserName, string Password, NetworkCredential nc2)
{
Cookie CurrentSiteCookie = null;
using (Authentication.Authentication authSvc = new Authentication.Authentication())
{
authSvc.Url = AuthenticationSiteURL + "/_vti_bin/authentication.asmx";
authSvc.CookieContainer = new System.Net.CookieContainer(); //create a new cookie container
//set the FBA login information
authSvc.AllowAutoRedirect = true;
authSvc.PreAuthenticate = true;
authSvc.Credentials = nc2;
Authentication.LoginResult result = authSvc.Login(UserName, Password);
if (result.ErrorCode == Authentication.LoginErrorCode.NoError)
{
try
{
CookieCollection cookies = authSvc.CookieContainer.GetCookies(new Uri(AuthenticationSiteURL));
CurrentSiteCookie = cookies[result.CookieName];
return CurrentSiteCookie;
}
catch (System.Exception ex)
{
//Console.WriteLine("Exception occured while calling lists.asmx" + ex.Message);
return CurrentSiteCookie;
}
}
else if (result.ErrorCode == Authentication.LoginErrorCode.PasswordNotMatch)
{
MessageBox.Show(this, "Password doesn't match. Please verify your password", "Test Connection", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
return CurrentSiteCookie;
}
else
return CurrentSiteCookie;
}
}
Hope this will help you.