2

Actually I am trying to add items in a share point List from a windows application. It all goes fine when I added the web reference and the able to get the all the offerings listed for Lists.asmx. When I execute my program and try to call listServiceObj.GetListAndview("Customers",""); It gives me error "The request failed with HTTP status 401: Unauthorized" . Please note that at this time my credentials and url of the service reference were;

        SpListService.Lists spListService = new SpListService.Lists();
        spListService.Credentials = System.Net.CredentialCache.DefaultCredentials;

        spListService.Url = "http://localhost/_vti_bin/Lists.asmx";


        XmlNode customerListView = spListService.GetListAndView("Customers", "");

Then I Changed the above code to ;

        SpListService.Lists spListService = new SpListService.Lists();
        spListService.Credentials = System.Net.CredentialCache.DefaultCredentials;

        spListService.Url = "http://<PC-Name>/sites/Home/_vti_bin/Lists.asmx";


        XmlNode customerListView = spListService.GetListAndView("Customers", "");

then I recieved the following error;

"Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."

I have made the logged in user in the group of full controll. also the member of the Administrator group.. but same result.... Also please note that when try and access "http://localhost/" or "http:///" it gives me access denied page of SP2010.... instead I have to write "http:///sites/Home/SitePages/Home.aspx" to open my team site collection

I really stuck in to this .... would be really pleased to have some solution to this problem of mine...... Thanks in advance MJay

  • Changing the Url to:"spListService.Url = "http://khilt-366/sites/Home/_vti_bin/Lists.asmx?wsdl" following error occured. Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/wsdl/ was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/. – user1897556 Dec 12 '12 at 12:18
  • As this is primarily an authentication issue, you should use a question topic that refers to such. – Petri K Dec 12 '12 at 12:26

1 Answers1

0

I had a similar problem when I implemented my first SharePoint lists Web Service client. The reason was that the autogenerated client class actually introduced itself as a Mozilla web browser by default! The SharePoint server did not allow basic authentication for browsers so the client was actually redirected to firewall login page.

I suggest you to inherit another class from the Lists class and do the following:

  1. Set another user agent value in constructor.
  2. Set the "preauthenticate" property to true. This should force the client to send the credentials in the first request, not only after they have been asked for.
  3. If necessary, try giving the credentials explicitly.

See the example below.

public class CustomizedLists : Lists
{
    public CustomizedLists() : base()
    {
        this.UserAgent = "Some SharePoint client";

        this.PreAuthenticate = true;

        System.Net.ICredentials creds = new System.Net.NetworkCredential("user", "pwd");
        this.Credentials = creds.GetCredential(uri, "Basic");
    }
}
Petri K
  • 341
  • 2
  • 9
  • Where to write this code ... I am actually try to consume this Lists.asmx service in a widows application.... I am very new at Share Point can you please guid me for the resolution. – user1897556 Dec 13 '12 at 07:12
  • The example has actually nothing to do with SharePoint as it is just basic object-oriented programming with C#. Just create a new class called "CustomizedLists" that follows the example. Don't forget namespaces! Then, when creating an instance of the Web Service client, use the _CustomizedLists_ class instead of _Lists_. – Petri K Dec 13 '12 at 08:41