¡¾·±ÌåÖÐÎÄ¡¿
¡¾ÉèΪÊ×Ò³¡¿
¡¾¼ÓÈëÊղء¿
µ±Ç°Î»Öãº.Net¼¼ÊõÊ×Ò³ >> °²È«ºÍÓÅ»¯ >> ¹þ¹þ ³ÉÀ² ΪWeb Service¿Í»§¶ËÈÏÖ¤É趨°²È«ÐÅÈÎ×´

¹þ¹þ ³ÉÀ² ΪWeb Service¿Í»§¶ËÈÏÖ¤É趨°²È«ÐÅÈÎ×´

2004-10-01 08:26:10  ×÷Õߣº  À´Ô´£º»¥ÁªÍø  ä¯ÀÀ´ÎÊý£º29  ÎÄ×Ö´óС£º¡¾´ó¡¿¡¾ÖС¿¡¾Ð¡¡¿
¼ò½é£º Sreedhar Koganti [@hotmail.com] Is any one got System.Net.WebException: The request failed with HTTP status 401: Access Denied. I created a web service. and i tested with test page. After...

Sreedhar Koganti [@hotmail.com]

Is any one got System.Net.WebException: The request failed

with HTTP status 401: Access Denied.

I created a web service. and i tested with test page.

After i counume it in aspx page[in the same machine] i got

the above error.

Is i am missing some thing, regaarding permissions.

Thansk

Sreedhar

Madhu [@microsoft.com]

This is permissions problem.

Can you please give me more info about this problem

(1)What is iis security you are implementing like anonymous,basic,..

(2)Are you able to browse web service from IE from remote machine

I have problem with similar eroor,may be going through this problem will

give you better idea on your problem

--------------------------------------------------

PROBLEM:

2 web sites hosted on a Windows 2000 machine. The default website has an

ASPX

WebForms page that calls into an ASMX Web Service. The second website is

mapped to a port other than 80. The webforms page executes without a

problem

if the call to the web services is commented out. The Web Service executes

without a problem if we browse to the ASMX file directly. When the Web

Service IIS application has anonymous access disabled then the following

error

is reported back to the WebForms page that tries to access it?

The request failed with HTTP status 401: Access Denied.

Description: An unhandled exception occurred during the execution of the

current web request. Please review the stack trace for more information

about

the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP

status

401: Access Denied.

Source Error:

An unhandled exception was generated during the execution of the current web

request. Information regarding the origin and location of the exception can

be

identified using the exception stack trace below.

Stack Trace:

[WebException: The request failed with HTTP status 401: Access Denied.]

System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClient

Mes

ssage message, WebResponse response, Stream responseStream) +1174

System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String

methodName,

Object[] parameters) +216 TestClients.ws.Service1.Test1() in

d:\worksets\vswebcache\dotnettest1_8080\testclients\web

references\ws\reference.cs:37 TestClients.WebForm1.btnTest1_Click(Object

sender, EventArgs e) in

d:\worksets\vswebcache\dotnettest1_8080\testclients\webform1.aspx.cs:51

System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo

stB

BackEvent(String eventArgument) +58

System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,

String eventArgument) +18

System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

System.Web.UI.Page.ProcessRequestMain() +1263

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

<>

RESOLUTION:

Proxy classes created using the Web Services Description Language (WSDL)

tool

(Wsdl.exe), or created when adding a Web reference in Visual Studio.NET,

derive from the SoapHttpClientProtocol class. These classes have a

Credentials

property, which can be used to get or set security credentials for Web

Service

client authentication.

To use the Credentials property, a Web Service client must create an

instance

of a class implementing the ICredentials interface, such as the

NetworkCredential class. Then the client must set credentials that are

specific to the authentication mechanism before making a call to a Web

Service

method.

Since Anonymous access was turned off for the Web Service application

requests

are required to provide credentials. By default calls to the proxy do not

inherit the credentials of the caller. This was the confusing part because

one would expect the calling thread to be running under the ASPNET account

and

the call would supply the credentials for this user by default (The ASPNET

account had access to all of the NTFS folders and files for the web service

application). Since no credentials are being supplied the request fails

with

401, Access Denied.

To set the credentials on the proxy before you make the call use

PROXY.Credentials = System.Net.CredentialCache.DefaultCredentials

Where PROXY is the name of the WebService Proxy.

NOTE: DefaultCredentials represents the system credentials for the current

security context in which the application is running. For a client-side

application, these are usually the Windows credentials (user name,

password,

and domain) of the user running the application. For ASP.NET applications,

the

default credentials are the user credentials of the identity for the asp

worker process, or the user being impersonated.

In our case the DefaultCredentials represents the ASPNET user account

because

we are not impersonating the caller.

---------------------------------------------------------------

Thanks,

Madhu

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

You assume all risk for your use. © 2001 Microsoft Corporation. All rights

reserved.

ÔðÈα༭£ºadmin
±¾ÎÄÒýÓõØÖ·£º http://www.3pcode.com/net/2004/10/7020.htm
Ïà¹ØÎÄÕÂ