首页 > 开发 > 综合 > 正文

为Web Service客户端认证设定安全信任状

2024-07-21 02:24:32
字体:
来源:转载
供稿:网友
,欢迎访问网页设计爱好者web开发。 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.
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表