Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am building an application on a different server, than that of the SharePoint 2010 foundation. But I want to be able to update some information / data in SharePoint Lists using Web Services.

I am trying to use /_vti_bin/authentication.asmx?WSDL. When Mode method is invoked i get Value: Windows Type: AuthenticationMode

When i try the Login method i get following results: String CookieName = null LoginErrorCode ErrorCode = NotInFormsAuthenticationMode Int32 TimeoutSeconds = 0

So the idea is not to use Forms Authentication but stick with windows authentication.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
Thanks!! Can you pls. let me know the namespace for the used class Authentication?? –  user8353 May 15 '12 at 10:01
add comment

If SharePoint is using Windows Authentication (which is the default) then all you need to do in your ASP.NET app is to attach credentials to the Web service proxy. To attach the credentials of the current user you would use something like:

proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

With that said, I would suggest that you take a look at the Client Object Model. It's much easier to use than SharePoint's SOAP Web services. For example, the Client Context object automatically attaches Windows credentials for you. If you are using forms-based authentication it has facilities to set the authentication mode and add the credentials of the forms-based user. No need to set cookies and so on.

You can get information in several places, here are two:

Microsoft SharePoint 2010 Developer Training Course http://msdn.microsoft.com/en-us/sp2010devtrainingcourse_clientobjectmodel_unit

Plualsight SharePoint 2010 Client Object Model Course (requires a subscription but you can get a free trial that will give you enough time to watch the course) http://www.pluralsight-training.net/microsoft/olt/Course/Toc.aspx?n=sp2010-client-object-model

One final option is to use the SharePoint REST APIs (oData service) to read and update the list data. This option is more lightweight than the client object model and may better suit your needs if you just care about data. Here's a resource that describes how to use the REST service.

REST and LINQ | SharePoint 2010 http://msdn.microsoft.com/en-us/sharepoint/ff462048

share|improve this answer
    
I have been searching for 2 days now for a method to use those REST services, but I can't figure out a way to obtain an access token. I want to access a sharepoint server from an iOS mobile app –  Radu Simionescu Mar 19 at 12:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.