The request failed with HTTP status 401: Unauthorized.

Feb 4, 2008 at 2:13 AM
Hi

I have successfully created the .smpl file using custom credentials, I can access the objects and create a linq query but when I run the console app I am getting the
The request failed with HTTP status 401: Unauthorized
Exception when I try and access the lists.

Cheers
Coordinator
Feb 7, 2008 at 7:11 AM
Hi,

I assume you're using the built-in web service provider based on what I infer from your explanation on how the spml got generated using custom credentials. Currently we don't store the user name and password used in entity generation in the generated code; this is done because most likely the developer will specify his/her own (administrator?) account while we don't want to:

a) leak those credentials
b) enforce that user account to be used at runtime

Instead, the used default account are the Windows network credentials of the user executing the code. If you want to override these, you'll have to set the Credentials property on the context object like this:

var ctx = new MySharePointDataContext();
ctx.Credentials = new NetworkCredential(user, password, domain);
...

This is consistent with the way generated web service proxies in .NET work (see http://msdn2.microsoft.com/en-us/library/system.web.services.protocols.webclientprotocol.credentials.aspx).

Thanks,
-Bart
Feb 7, 2008 at 8:21 AM
Thanks Bart works perfectly , I am looking forward to the prod release

Cheers