.NET Framework - 401 While Accessing Web Service
Asked By Ben
01-May-08 11:07 PM
I'm trying to access a c# web service from a web form.
I set up the web reference proxy object as follows:
proxy.PreAuthenticate = true;
proxy.Credentials = CredentialCache.DefaultCredentials;
but i get a 401 error. If I switch the IIS website from Integrated
Windows Auth to Anonymous, it works... but i want it to use windows
security.
my web.config of the web form is set to imperonsate the logged on
user, and i verified that's working by checking that
this.User.Identity.Name is my domain user (which has access to the web
service).
Any ideas what i'm doing wrong? (btw, the web service is SSL if that
makes a difference).
Thanks!
Visual Studio
(1)
CredentialCache
(1)
IIS
(1)
PreAuthenticate
(1)
Enhancement
(1)
Windows
(1)
Auth
(1)
Fb427b2547e6
(1)
Nirosh replied...
http://www.dotnetbips.com/articles/dbd724e9-78f0-4a05-adfb-190d151103b2.aspx
check this and see..
--
L.W.C. Nirosh
Ben replied...
thanks,
anyway to do it without using web form authentication?
the crazy thing is that if i fire up my web form from Visual Studio it
works just fine and can access the web service, but if i publish it to
another server and try from there I get the 401 (the site i'm
publishing to is using 'intergrated windows auth') .
Nirosh replied...
okay, check WSE (Web Service Enhancement) to see how to improve the web
service security..
to avoid the dependacy with integrated authentication, create a new web site
for your web service, that way it should work fine.
--
L.W.C. Nirosh
thanks,
anyway to do it without using web form authentication?
the crazy thing is that if i fire up my web form from Visual Studio it
works just fine and can access the web service, but if i publish it to
another server and try from there I get the 401 (the site i'm
publishing to is using 'intergrated windows auth') .
Ben replied...
te
I'm using VS2008... is there WSE for that version? i can only find it
for VS2005?
is this the only way? i made C# web services before that were hosted
on an IIS site with intergrated windows auth, but the client side was C
++ and i was able to pass current nt credentials without a problem....
this is my first attempt where the client side is another c# web page.
Nirosh replied...
I am not sure whether this is the only way.. When you say it worked with C++
and now is not working with aspx/c# web site, that is interesting..
The WSE 3.0 should work fine with framework 3.0/3.5. But if you want it to
work with VSS 2008 IDE then you need to trick it.
e.g.:-
http://devlicio.us/blogs/derik_whittaker/archive/2008/04/03/wse-3-0-support-in-visual-studio-2008-hack.aspx
But I din't do this.. so please do it with extra care..
--
L.W.C. Nirosh
I'm using VS2008... is there WSE for that version? i can only find it
for VS2005?
is this the only way? i made C# web services before that were hosted
on an IIS site with intergrated windows auth, but the client side was C
++ and i was able to pass current nt credentials without a problem....
this is my first attempt where the client side is another c# web page.
Ben replied...
++
s...
.
..
eb
de quoted text -
I switched the project to VS2005 just to test and enabled WSE 3.0
support -- is there any additional settings i need to change since it
still throws the same error...
Nirosh replied...
You need to get the web service configure into a another web site, then you
can remove the integrated authentication just for that web site.. then your
web service will be vulnerable, so to improve security use the WSE..
just converting the project to 2005 and enable wse won't do any good. as the
webservice is still having integrated security..
--
L.W.C. Nirosh
I switched the project to VS2005 just to test and enabled WSE 3.0
support -- is there any additional settings i need to change since it
still throws the same error...
Ben replied...
u
r
he
to
0-s...
b
b
..
...
m...
s
at
-
so are u saying I cannot use integrated security on a WS?
btw, it works fine if my client is a C# windows form (instead of a web
form)... so I think this shows the WS is okay... it's just there's
something i'm missing on the web form to make it work... but
everywhere i read i see they just say to set the Credentials param and
i did that already.
brucebarke replied...
you are hitting the one hop rule with nt creditals. it should work if you hit
the web site locally, but not from another computer.
to do this you have two options:
1) switch to basic, which will give the web server a primary token it can
use to access a second server.
2) switch to kerberos and enable server credentials delegation.
-- bruce (sqlwork.com)
Ben replied...
On Apr 29, 5:58=A0pm, bruce barker
hit
for option 1 it sounds like i'll need to know the user/pwd which i
won't...
option 2 sounds interesting... is this a complicated thing to setup?
i've been trying to search on the issue and haven't found a good
description on how to set it up yet... if anyone has any further info
on it i'd really appreciate it!
Thanks!!!

CredentialCache.DefaultCredentials .NET Framework Hi I'm using the following code to get a response froma I don't understand where the credentials are stored on the client, i.e. the Visual Studio web server. How do I clear them? What are DefaultCredentials? The username and password I them up from. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https: / / a.server.com / admin"); request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); If someone provides me with a username and password the Integrated Security how to I explicitly set the credentials? thanks Andrew ASP.NET Discussions Visual Studio (1) CredentialCache.DefaultCredentials (1) HttpWebResponse (1) HttpWebRequest (1) WebRequest.Create (1) NetworkCredential (1) CredentialCache (1) WebRequest (1) the defaultCredential is the nt identity of the current thread. to connect
what would cause this and how to get rid of it? Mark VB.NET Discussions Visual Studio (1) Vista (1) CredentialCache (1) ASP.NET (1) XP (1) VB (1) WebResources (1) FCzel (1) s ode and you might need to disable UAC, apparently a recent patch has caused some issues with Visual Studio and UAC, a friend from work was having similar troubles. Thanks, Seth Rowe [MVP] Nope similar issue recently, though in csharp. Had to do this: service.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; Hope this helps. . . Thanks for the reply. Where did you put this line? Was
MySite / Subsite / ? I am using MOSS 2007 as well. - - .NET Web Services Discussions System.Net.CredentialCache.DefaultCredentials (1) Visual Studio 2005 (1) Windows Server (1) SharePoint (1) CredentialCache (1) WebReference (1) MOSS 2007 (1) MyWebReference.Lists (1) What's in address element of should or should not be happening? - - From the WSDL you've posted, it appears that Visual Studio 2005 is doing the right thing. It's using the URL specified in the WSDL new myWebReference.Lists(); ws.Url = "http: / / site / SUBSITE / _vti_bin / lists.asmx"; ws.Credentials = System.Net.CredentialCache.DefaultCredentials; WSS v3 i think is at fault here. . . I've learned a bit more
null, "LocalSchema.xsd"); schemaSet.Compile(); / / BANG! XmlSchemaException thrown! / / . . . etc . . . What is really strange is that Visual Studio is resolving everything perfectly within the IDE. if I set up a test XML file me-com:TestLocal" xmlns:imp = "urn:schemas-me-com:Test"> Any ideas? Dave Xml Discussions Visual Studio (1) CredentialCache.DefaultCredentials (1) XmlSchemaSet.Compile (1) XmlSchemaException (1) XmlSchemaSet (1) ValidationType.Schema (1) CredentialCache (1) ReaderSettings.ValidationType (1) Solved the problem. My localhost was using Integrated Windows Authentication. I had to specify the credentials for the XmlResolver: XmlUrlResolver resolver = new XmlUrlResolver(); resolver.Credentials = CredentialCache.DefaultCredentials; schemaSet.XmlResolver = resolver; Hope it helps someone else! keywords: XmlSchemaException, on, XmlSchemaSet.Compile(), with