Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I m trying to hit SP Online asmx web services and update a list item. I have the code below which I m trying to run.

        /*Declare and initialize a variable for the Lists Web service.*/
        webReference.Lists listService = new webReference.Lists();

        SecureString password = new SecureString();
        foreach (char c in "password".ToCharArray()) password.AppendChar(c);

        listService.Credentials = new SharePointOnlineCredentials("", password);

        /*Set the Url property of the service for the path to a subsite.*/
        listService.Url = "";

        /*Get Name attribute values (GUIDs) for list and view. */
        System.Xml.XmlNode ndListView = listService.GetList("ListName");
        string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
        string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

        /*Create an XmlDocument object and construct a Batch element and its attributes. Note that an empty ViewName parameter causes the method to use the default view. */
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
        batchElement.SetAttribute("OnError", "Continue");
        batchElement.SetAttribute("ListVersion", "1");
        batchElement.SetAttribute("ViewName", strViewID);

        /*Specify methods for the batch post using CAML. To update or delete, specify the ID of the item, and to update or add, specify 
        the value to place in the specified column.*/
        batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
            //"<Field Name='ID'>new</Field>" +
           "<Field Name='Title'>New Item</Field></Method>";

        /*Update list items. This example uses the list GUID, which is recommended, but the list display name will also work.*/
            listService.UpdateListItems(strListID, batchElement);
            Console.WriteLine("Item Added");
        catch (Exception ex)

Updated I m getting the following error at listService.GetList("ListName") + Stack Trace

 Server was unable to process request. ---> Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

 at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
 at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
 at WebApplication1.webreference.Lists.GetListAndView(String listName, String viewName) in e:\Code\WebApplication1\WebApplication1\Web References\webreference\Reference.cs:line 262
 at WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in e:\Code\WebApplication1\WebApplication1\WebForm1.aspx.cs:line 28
 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
 at System.Web.UI.Control.OnLoad(EventArgs e)
 at System.Web.UI.Control.LoadRecursive()
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
share|improve this question
Since SOAP web services are officially deprecated, why just not to utilize CSOM or REST APIs? – Vadim Gremyachev Jun 12 '14 at 14:05
Just because it is deprecated doesn't mean it still can't be used for the forseeable future. InfoPath is officially deprecated and there are still a ton of questions here about InfoPath. – Eric Alexander Jun 12 '14 at 15:03
what is the error, could you please post the complete error? – Waqas Sarwar MCSE Jun 13 '14 at 4:18
I have updated the exception details along with the stack trace. – bkk Jun 13 '14 at 5:43

1 Answer 1

The following example demonstrates how to authenticate SharePoint SOAP Services in SharePoint Online using SharePointOnlineCredentials class :

public static CookieContainer GetAuthCookies(Uri webUri, string userName, string password)
    var securePassword = new SecureString();
    foreach (char c in password) { securePassword.AppendChar(c); }
    var credentials = new SharePointOnlineCredentials(userName, securePassword);
    var authCookie = credentials.GetAuthenticationCookie(webUri);
    var cookieContainer = new CookieContainer();
    cookieContainer.SetCookies(webUri, authCookie);
    return cookieContainer;


using (var listsProxy = new Lists())
     listsProxy.Url = webUri + "/_vti_bin/Lists.asmx";
     listsProxy.CookieContainer = GetAuthCookies(webUri, userName, password);

     //Invoke GetListCollection operation
     var result = listsProxy.GetListCollection();
     var xmlResult = XDocument.Parse(result.OuterXml);
     XNamespace s = "";
     var listEntries = from e in xmlResult.Descendants(s + "List")
                         select new
                                  Title = e.Attribute("Title").Value
share|improve this answer

Your Answer


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.