Not able to access list from SharePoint online site using lists.asmx web service

Hi,

I have to access a SharePoint online list using lists.asmx web service. Refer below code:

QaTest.Lists List = new QaTest.Lists();
            System.Net.NetworkCredential Credentilas = new System.Net.NetworkCredential("SPOLoginName", "SPOPassword");
            List.Url = "https://Test947.sharepoint.com/sites/at/_vti_bin/lists.asmx";
            List.Credentials = Credentilas;
            XmlNode ListItems1 = List.GetList("{CC16E6EE-0686-4115-A786-A37F7622A94B}");

Getting access denied error while accessing it. But, same code is working fine for on premises environment.

So, is there any way to access SharePoint online list using web service??

Thanks,

August 1st, 2014 1:53pm

The standard SharePoint web services are deprecated so I don't recommend using these in SharePoint Online. I recommend using the SharePoint Client Object Model. However, you can use the SharePointOnlineCredentials class which is part of the Client Object Model to set your credentials and set the CookieContainer of the Lists proxy which is required for SharePoint Online. Below are two methods showing you how to get the SharePointOnlineCredentials and from this getting the CookieContainer.

public static CookieContainer GetO365CookieContainer(SharePointOnlineCredentials credentials, string targetSiteUrl)
{

            Uri targetSite = new Uri(targetSiteUrl);
            string cookieString = credentials.GetAuthenticationCookie(targetSite);
            CookieContainer container = new CookieContainer();
            string trimmedCookie = cookieString.TrimStart("SPOIDCRL=".ToCharArray());
            container.Add(new Cookie("FedAuth", trimmedCookie, string.Empty, targetSite.Authority));
            return container;


        }

        public static SharePointOnlineCredentials GetO365Credentials(string userName, string passWord)
        {
            SecureString securePassWord = new SecureString();
            foreach (char c in passWord.ToCharArray()) securePassWord.AppendChar(c);
            SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(userName, securePassWord);
            return credentials;
}

Free Windows Admin Tool Kit Click here and download it now
August 2nd, 2014 4:16am

So, you are saying we can not use the standard way to communicate through web service in SharePoint online? There is only one way and that is CSOM?

Yes, I can get the access to the list using the method which you have provided. Thanks for that...

But, same method is not working with those SharePoint online sites or Tenants which have ADFS (Dir sync with Office 365) to authenticate. Is there any way to achieve the same for those sites as well?

August 2nd, 2014 5:25pm

Can you explain what the problem is with ADFS? Is the FedAuth cookie not there?
Free Windows Admin Tool Kit Click here and download it now
August 4th, 2014 2:54am

Got that working...thanks again.
August 4th, 2014 7:55am

This seems to be have broken recently. Unfortunately Lists.asmx is still the only way of getting field/column data from old versions of items/documents.
Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 9:09pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics