Ask a questionAsk a question
 

AnswerIssue accessing Sharepoint Web Server

  • Friday, November 06, 2009 5:02 PMxs2abhishek Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,

    I'm trying to access our sharepoint site to add some items in one of the lists on the site. Since the site is on a hosted server I decided to use the web services exposed by http://<server-url>/_vti_bin/lists.asmx , because of the requirements I have to access the same site to read some lists, I was successful to read the list which is on a "hosted environment", but when I try adding some items to the list I'm getting the Exception "System.Net.WebException: The request failed with HTTP status 401: Unauthorized", but I think I'm am passing the correct credentials as I used the same credentials to read the list. I'm am a little confused on this exception, since I gave anonymous access too. I'm a complete fresher to .net services. Here is the code snippet:-

    SharePointService.Lists listService = new SharePointService.Lists();
               
                //Authenticate the user by passing their credentials
                listService.Credentials = new NetworkCredential("xxxx", "xxxx", "xxxx");

                //Set the URL property of the service for the path to substitute
                listService.Url = listService.Url = "https://xxxx/_vti_bin/lists.asmx";

                try
                {
                    XmlNode list = listService.GetList("GUID of the List");
                    Console.WriteLine("Node Value:-> " +list);

                    Console.Read();
                }
                catch (Exception e)
                {
                    Console.WriteLine("" + e);
                }
                Console.Read();

    Thanks for the Help in advance !
    Abhishek

Answers

  • Saturday, November 14, 2009 6:01 PMxs2abhishek Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello:

    I think I found the solution to the problem...

    Using:-

    listService.Url = "https://xxxxxxxxx/_vti_bin/lists.asmx";
    listService.Credentials = new NetworkCredential("xxxx", "xxxx");

    Instead of :-

    listService.Credentials = new NetworkCredential("xf", "xf", "https://xxxxx");

    makes it working... Does anyone know why is this happening??

    Thanks,
    Abhishek
    • Marked As Answer byxs2abhishek Saturday, November 14, 2009 6:01 PM
    •  

All Replies

  • Friday, November 06, 2009 5:07 PMSteve.CurranMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If the GetList method works but when you add an item to the list (Assuming you are using UpdateListItems method) you receive a 401 un-authorized. It appears that you have only read access to the list. Can you check with your host provider what permissions you have on this list?
    certdev.com
  • Friday, November 06, 2009 7:24 PMxs2abhishek Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Steve,

    Thanks for your reply ! I have still reached that point of using updateListItems. I made two different classes to test the two things, the first one used
    " System.Xml.XmlNode activeItemData = listService.GetListItems(listGUID, activeItemViewGUID, null, null, "9000", null, ""); " and it worked, but now when I'm using
    " XmlNode list = listService.GetList("{6FDC42EC-E8B3-4279-91EB-0A2468861542}"); " to get the list details then I see that error. Do you know how can we get the actual field names of the list. I'm following this tutorial http://www.scribd.com/doc/9142948/Accessing-SharePoint-Data-Using-C-Without-Running-Code-on-SharePoint-Server-Part-3.

    Please let me know if I'm on the right track for attacking this issue. I'm still learning sharepoint!

    Thanks for the Help!
    Abhishek
  • Friday, November 06, 2009 9:17 PMxs2abhishek Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello:

    There is one more goofy thing which I'm encountering, when I use " listService.Credentials = new NetworkCredential("xf", "xf", "https://WEBSITE-NAME.net"); " even if I give fake credentials like "xf" and "xf" it still works !! Where does windows authentication go in this case. How is that possible ? Am I missing something here ? If anyone knows whats happening here, please let me know !! :)  Don't know weather this would help, but I'm working on Windows Vista and trying to access sharepoint services on an hosted environment !!

    Thanks,
    Abhishek
  • Saturday, November 07, 2009 12:00 AMSteve.CurranMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    So you are now getting the 401 error when accessing GetList. Did you check with your host provider what access you have? I do believe you need at least contributor permissions to get data back on the GetList method. If the service takes any credentials then the host provider must have anonymous access turned on. And the IUSER_xxx account must only have read access to SharePoint.
    certdev.com
  • Saturday, November 07, 2009 1:05 AMxs2abhishek Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks Steve ! Okay.. So we have a website hosted on "mailstreet" I have been given all rights i.e I can add,delete,modify - users,lists,documents etc, and I'm using my credentials, which is use when I log in from a web browser, and I have also checked for the contributor permission, I have the contributor permission and I am giving my authentication credentials to the web service. I did turn on  anonymous access [ Site Actions --> Site Settings --> Advanced Permission --> Settings --> Anonymous Settings --> Anonymous users can access (Entire Web Site) ]. So, I guess this is how we have to turn on anonymous access. So even if I am able to read lists from Sharepoint Web site I'm still not able to add items to the list ! I am completely following this tutorial ( http://www.scribd.com/doc/9142948/Accessing-SharePoint-Data-Using-C-Without-Running-Code-on-SharePoint-Server-Part-3 ). I really appreciate your help !

    Thanks,
    Abhishek
  • Saturday, November 14, 2009 6:01 PMxs2abhishek Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello:

    I think I found the solution to the problem...

    Using:-

    listService.Url = "https://xxxxxxxxx/_vti_bin/lists.asmx";
    listService.Credentials = new NetworkCredential("xxxx", "xxxx");

    Instead of :-

    listService.Credentials = new NetworkCredential("xf", "xf", "https://xxxxx");

    makes it working... Does anyone know why is this happening??

    Thanks,
    Abhishek
    • Marked As Answer byxs2abhishek Saturday, November 14, 2009 6:01 PM
    •