Can't authenticate to lists.asmx web service

Discussion in 'ASP .Net Web Services' started by bparker, Nov 14, 2006.

  1. bparker

    bparker Guest

    I'm trying to add an item to a sharepoint list using the Sharepoint
    Lists web service. The code works fine when I set the credentials to
    use DefaultCredentials. But I want to specify in code which user
    account to use when calling the webservice b/c normal users do not have
    access to write to this list. My code is as follows

    Dim ListService as new WebService.Lists
    ListService.Credentials = New System.Net.NetworkCredential("username",
    "password", "domain")
    ListService.Url = "http://myServerUrl/SubArea/_vti_bin/lists.asmx"
    ListService.UpdateListItems("My List", camlBatch)

    When I have the second line as ListService.Credentials =
    System.Net.CredentialCache.DefaultCredentials it works fine. But when I
    create a new credential using the same name/password as my current
    logged in user it fails. I get the error "The request failed with HTTP
    status 401: Unauthorized." for the UpdateListItems call.

    I have found many cases where people can get this to work by passing
    usernames/passwords and it doesn't work with default credentials, but
    I'm the opposite, I can't get the call to work when passing a set of
    credentials to the web service.

    Anyone have any recommendations or troubleshooting ideas?

    Thanks,
    Brian
     
    bparker, Nov 14, 2006
    #1
    1. Advertising

  2. bparker

    bparker Guest

    I finally got this to work after beating it to death.

    I added the following code:
    Dim myCache as new CredentialCache
    Dim myCredentials as new NetworkCredential

    With myCredentials
    .UserName = "username"
    .Password = "password"
    .Domain = "domain"
    End With

    myCache.Add(New Uri("ServerURL/_vti_bin/lists.asmx"), "Digest",
    myCredentials)
    ListService.Credentials = myCache.DefaultCredentials


    I had tried this same code many times over because of a post I read
    regarding assigning the ListService credentials = myCache. BUT it only
    works for me when I specify myCache DefaultCredentials...

    Was painful to discover the correct syntax but now I can finally move
    forward. Hope someone else can benefit from this.

    Brian


    bparker wrote:
    > I'm trying to add an item to a sharepoint list using the Sharepoint
    > Lists web service. The code works fine when I set the credentials to
    > use DefaultCredentials. But I want to specify in code which user
    > account to use when calling the webservice b/c normal users do not have
    > access to write to this list. My code is as follows
    >
    > Dim ListService as new WebService.Lists
    > ListService.Credentials = New System.Net.NetworkCredential("username",
    > "password", "domain")
    > ListService.Url = "http://myServerUrl/SubArea/_vti_bin/lists.asmx"
    > ListService.UpdateListItems("My List", camlBatch)
    >
    > When I have the second line as ListService.Credentials =
    > System.Net.CredentialCache.DefaultCredentials it works fine. But when I
    > create a new credential using the same name/password as my current
    > logged in user it fails. I get the error "The request failed with HTTP
    > status 401: Unauthorized." for the UpdateListItems call.
    >
    > I have found many cases where people can get this to work by passing
    > usernames/passwords and it doesn't work with default credentials, but
    > I'm the opposite, I can't get the call to work when passing a set of
    > credentials to the web service.
    >
    > Anyone have any recommendations or troubleshooting ideas?
    >
    > Thanks,
    > Brian
     
    bparker, Nov 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    451
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  2. JeremyPollack
    Replies:
    0
    Views:
    464
    JeremyPollack
    Jun 26, 2007
  3. Brad Leach

    Using a Web Service to Authenticate Users

    Brad Leach, Sep 22, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    150
    Brad Leach
    Sep 22, 2003
  4. Matt
    Replies:
    1
    Views:
    668
    Dan Rogers
    Nov 11, 2004
  5. Peter Bradley

    Authenticate to a Web Service

    Peter Bradley, Jun 20, 2008, in forum: ASP .Net Web Services
    Replies:
    7
    Views:
    1,716
    Peter Bradley
    Jun 28, 2008
Loading...

Share This Page