HTTP status 401: Access Denied

I am trying to programtically execute an MS SQL Server Reports Server Service in a web application. "/ReportServer/ReportService.asmx">http://<Server>/ReportServer/ReportService.asmx" I am receiving an "The request failed with HTTP status 401: Access Denied." I have tried using "DefaultCredentials" and Network Credentials that have local administrator rights on the Report Server computer.
Below is the code I am executing.
This same code works fine in a console application.
Any ideas of what I can try to resolve the error?
Thanks in advance, Ken

Private Sub Page_Load()
Try
'Rem OurSQLReportsServer.Url = "http://OurSQLReportsServer/ReportServer/ReportService.asmx"
Dim svc As New OurSQLReportsServer.ReportingService
svc.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim CatalogItems() As OurSQLReportsServer.CatalogItem
CatalogItems = svc.ListChildren("/", True) '<- Errors Here
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub

[1263 byte] By [KLomax] at [2007-12-17]
# 1

OK so you have a client computer C that connects to a Middle tier ASMX page that connects to the SQL Server Computer S. [as far as I can understand]
You also say that the console app works. Where is the console app located? on C or on M?

Two things to consider.
1. When you say default credentials, it can mean two things.
a) Are you authenticating from C to M?
If so the default credentials may be the credentials of the authenticated user.
Please print the WindowsIdentity.GetCurrent().Name. It will tell you exactlt who the
user you are authenticating as. In many cases, if you are authenticating from C to M, you can't use the default credentials since the delegation does not work.
b) If you are not authenticating from C to M most probably the Current Identity is
either ASPNET user or the Netwrk Service Account, both don't have the permission to
acces the SQL Server on the machine M

2. Now if you are using explicit credentials that has the Administrative Rights on the
SQL computer, things should work. I can't imagine why it won't work.
I would try opening a connection to the SQL server using the ADO connection objects with a connection string. You might get better error if you do so and you can
start debugging from there.

Let me know how this goes.
Also let us know the server versions, and the framework version.

Thanks

DurgaprasadGorti at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2
I found the problem.
I had to use network credentials.
The first time I tried using network credentials, I was not referencing the correct Uri in my
Credential.Add statement. So the authentication failed.

Dim svc As New <Server>.ReportingService
Dim CatalogItems() As <Server>.CatalogItem
Dim Credential As System.Net.CredentialCache = New System.Net.CredentialCacheCredential.Add(New Uri("/ReportServer/ReportService.asmx">http://<Server>/ReportServer/ReportService.asmx"), "Negotiate", New System.Net.NetworkCredential(Global.UserID, Global.Password, "MyNet"))svc.Credentials = Credential
CatalogItems
= svc.ListChildren("/", True)



KLomax at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3
Thank you for your assistance.
The Identity was local\IUSR_local for the DefaultCredentials.
I have found the answer. I was not correctly creating the network credentials.
See other post back

Regards,
Ken

KLomax at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 4

I am glad it is working, but I think assigning a fixed network credential should work.
We should be using that particular credential to go to that request.
Can you please create a networkcredential without the URI and see if it works?

DurgaprasadGorti at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 5

Yes, it does work.

Dim svc As New <Server>.ReportingService
svc.Credentials = System.Net.NetworkCredential(UserID, Password, "Mynet")

Thank you,
Ken

KLomax at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 6
Hi, I had presented the same problem. I suggest using this implementation:

wsDemo : it's the web service.

...
Imports System.Net
...
wsDemo.Credentials = New System.Net.NetworkCredential("userName", "password", "Domain")

wsDemo.foo ()
I Hope that this code help you.

KLomax wrote:

I am trying to programtically execute an MS SQL Server Reports Server Service in a web application. "/ReportServer/ReportService.asmx">http://<Server>/ReportServer/ReportService.asmx" I am receiving an "The request failed with HTTP status 401: Access Denied." I have tried using "DefaultCredentials" and Network Credentials that have local administrator rights on the Report Server computer.
Below is the code I am executing.
This same code works fine in a console application.
Any ideas of what I can try to resolve the error?
Thanks in advance, Ken

Private Sub Page_Load()
Try
'Rem OurSQLReportsServer.Url = "http://OurSQLReportsServer/ReportServer/ReportService.asmx"
Dim svc As New OurSQLReportsServer.ReportingService
svc.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim CatalogItems() As OurSQLReportsServer.CatalogItem
CatalogItems = svc.ListChildren("/", True) '<- Errors Here
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub

GermanMasis at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 7
Hi
I am calling SQL reporting web service from vb.net windows application.
I set the credentials to defaultcredentials. ReportingServer is set to
use Windows Integrated authentication and no anonymous access.
When calling, it throws HTTP 401 Unauthorize error. Please let me know
the problem reason and solution. (looks like defaultcredentials is
blank). How can I pass the current user credential who is running the
exe. I do not want to create credentials using id and password. My goal is to pass the credentials of the user running the windows application

(note: The report being called has datasource with different id and password stored in datasource to avoid double-hop to another sql serve machine)

Regards,
Vasanth

bvasanth at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 8

Please start a different thread.
Once a question is answered we may not look at the follow up questions.
In any case your app should work.
DefaultCredentials is indeed blank but that's just implementation
Internally we look at the current user's token.
Let me know what does not work and what the exception and stack trace is.
Better yet show a netmon or system.net trace.
Look at http://blogs.msdn.com/dgorti

DurgaprasadGorti at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 9
Thanks Durga. I have started new posting with exception info
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=154950&SiteID=1
bvasanth at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified