Can't authenticate to lists.asmx web service

B

bparker

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
 
B

bparker

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top