4

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.

1
  • @John : How to pass the User name and password to the authentication method? I am getting the error "Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'" when I am passing the username and password to the method. Also where to pass the domain in you code? The parameters to you method do not include domain. Regards Agasthya
    – agasthya
    Commented Sep 12, 2017 at 11:49

3 Answers 3

3

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.

1
  • 1
    Thanks!! Can you pls. let me know the namespace for the used class Authentication??
    – user8353
    Commented May 15, 2012 at 10:01
2

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

1
  • 1
    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 Commented Mar 19, 2014 at 12:20
0

System will not let me comment.....

@user8353 if you are still looking for the answer. Authentication is not a class. In @ashish.chotalia answer, Authentication is a reference to the WSS 3.0 authentication.asmx web service.

Create a reference to that web service exactly as you would for the lists web service and use that where his example uses Authentication....

url is https://yoursite.com/_vti_bin/authentication.asmx

hth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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