473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

401 error accessing web service using credentials

I'm setting up my new pc with all my VS.net projects and I'm missing
something.....something I've done many times before without problem. I
have several asp.net apps accessing secure .net web services (secure meaning
windows authentication credentials must be used to access the web services).
The problem is that when the web apps attempt to access a web service they
are receiving 401: unathorized.

- The apps are all running on web sites on my pc.
- I have created the local user accounts
- Set up the web services to require windows authentication (both in the
web.cofnig and in the iis settings..anonymous is turn off) and to allow only
me and the user for app authentication.
- Required user is included in the folder level access permissions.
- I have accessed several of the service asmx files via web browser and I
authenticate successfully (I even removed my access in the web.config to
confirm that authentication would fail without)

In the web app that accesses the service I am using credential caching and
pre authenticating
Dim cache As New CredentialCache
Dim user As String = "myuser"
Dim password As String = "mypassword"
cache.Add(New Uri(ws.Url), "Negotiate", New NetworkCredential(user,
password, domain))
ws.Credentials = cache
ws.PreAuthenticate = True

In the web service configs
<authentication mode="Windows"/>
<authorization>
<allow users="mypc\wsuser, companydomain\myuser"/>
<deny users="*"></deny>
</authorization>

When I look at the security event logs I can see a Success event for NETWORK
SERVICE using the credentials, followed immediately by a Failure event for
SYSTEM using the same user name "Reason: An error occurred during logon".
On my old pc it works and the security event logs correctly shows the
supplied user name logging on instead of the SYSTEM user failure. I have
event changed the web apps to use my personal login information and the same
problem occurs.

Since these same apps work on my old pc and for others here. What the heck
am I missing?

Brad
Dec 19 '06 #1
3 7715
Hello Brad,

From your description, you're encountering some access/authentiation error
when calling an ASP.NET webservice which is secured through integraetd
windows authentication.

As for the code you used, I think it is quite correct, below is my local
test code that runs well.(on windows 2003 server IIS6/asp.net2.0)

==================
private void btnGetCollection_Click(object sender, EventArgs e)
{
SessionService.Service service = new
SessionServiceClient.SessionService.Service();

CredentialCache cc = new CredentialCache();

NetworkCredential nc = new NetworkCredential("WSEUser",
"Password", "machinename");

cc.Add(new Uri(service.Url), "Negotiate", nc);

service.Credentials = cc;
service.PreAuthenticate = true;
DataTable dt = service.GetTable();

StringWriter sw = new StringWriter();
dt.WriteXml(sw);
txtContent.Text += "\r\nnums: " + sw.ToString();

}
=====================

Also, as you said the program used to work well on another box, I think
this should be an environment specific(such as configuration) issue. You
can try testing through the following routine:

** since you've changed the server machine, check whether the client
application's code or server service's web.config's settings as refer to
the new machine name in username prefix (e.g newmachinename\username).
This is important when you use a local account on the server machine to
access the service.

** You can event firstly comment the authorization setting in web.config
(as below)

<!--
<authorization>
<allow users="machinename\WSEUser"/>
<deny users="*"></deny>
</authorization>
-->
to see whether it is this setting that cause the issue.

in addition, the IIS log is also what you can check. If the IIS log
indicate that there is 401 error from your webservice client, that means
the authentication at IIS layer failed (hasn't even reach ASP.NET layer)

Please feel free to let me know if you have any other finding or question.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Dec 19 '06 #2
See link below. The kb article's workaround to disable the loopback check
resolved the problem.

http://support.microsoft.com/default...b;en-us;896861

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:FV**************@TK2MSFTNGHUB02.phx.gbl...
Hello Brad,

From your description, you're encountering some access/authentiation error
when calling an ASP.NET webservice which is secured through integraetd
windows authentication.

As for the code you used, I think it is quite correct, below is my local
test code that runs well.(on windows 2003 server IIS6/asp.net2.0)

==================
private void btnGetCollection_Click(object sender, EventArgs e)
{
SessionService.Service service = new
SessionServiceClient.SessionService.Service();

CredentialCache cc = new CredentialCache();

NetworkCredential nc = new NetworkCredential("WSEUser",
"Password", "machinename");

cc.Add(new Uri(service.Url), "Negotiate", nc);

service.Credentials = cc;
service.PreAuthenticate = true;
DataTable dt = service.GetTable();

StringWriter sw = new StringWriter();
dt.WriteXml(sw);
txtContent.Text += "\r\nnums: " + sw.ToString();

}
=====================

Also, as you said the program used to work well on another box, I think
this should be an environment specific(such as configuration) issue. You
can try testing through the following routine:

** since you've changed the server machine, check whether the client
application's code or server service's web.config's settings as refer to
the new machine name in username prefix (e.g newmachinename\username).
This is important when you use a local account on the server machine to
access the service.

** You can event firstly comment the authorization setting in web.config
(as below)

<!--
<authorization>
<allow users="machinename\WSEUser"/>
<deny users="*"></deny>
</authorization>
-->
to see whether it is this setting that cause the issue.

in addition, the IIS log is also what you can check. If the IIS log
indicate that there is 401 error from your webservice client, that means
the authentication at IIS layer failed (hasn't even reach ASP.NET layer)

Please feel free to let me know if you have any other finding or question.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Dec 19 '06 #3
Thanks for your followup Brad,

So the issue is due to the IIS site on the new server is not using the
default IP address setting (or use a custom host header), this does be an
known issue of IIS which may influence the integrated windows
authentication behavior. Anyway, glad that you've figured out the issue. If
you meet any new problems later, please feel free to post here.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Dec 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff | last post by:
Has anyone had any luck accessing an Oracle database from a web service? I have a C# DLL with various code to query an Oracle database. If I call the methods in this DLL from a Windows Forms...
0
by: FleaBite | last post by:
Hi, I have developed a web service in PHP using NuSOAP. I want some form of security for this WS, so I've put it in a directory which is password protected, using an htaccess file. The...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
4
by: John | last post by:
Hi My first web service seems to be OK as I can put its url in explorer and can use the invoke button to view the returned data as xml. The problem comes when I call it form a client app using;...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
2
by: Terry Holland | last post by:
I posted a follow up to an earlier post but did not receive response so here it is again (with original post and response) > This could be because you are running the index service over this web...
3
by: Khalique | last post by:
Problem: Accessing web service causes exception – “The request failed with HTTP status 401 : Access Denied”. I created a web service on my local machine and then developed a separate test...
5
by: Khalique | last post by:
Hi everyone, I Hope that someone will be able to give me a hint to the solution to my problem. I have developed a web service (vb.net) that needs to access the folders / files and copy files to...
4
by: Khalique | last post by:
I have built a web service whose purpose is to copy files from a secure place to client machine and vice versa. The problem I am having is perhaps related to permissions and access rights. For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.