我有一个ASMX web服务(在我的本地主机-WinXP IIS 5.1上),我从web客户端调用它。我的web服务必须使用另一个ASMX web服务(在Win 2003服务器IIS 6.0上)。
当我以“硬编码”的方式在Web服务代码中提供凭据时:
engineWSE.Credentials = new System.Net.NetworkCredential("myUser", "myPass", "myDomain");
…远程web服务的后续调用工作正常。
现在,我正试图在一些初步测试中模仿自己。我对这一点的初步了解告诉我,这可能是一个很大的主题,但以下是我为初学者所做的工作:
UNCHECKED "Anonymous access" in my virtual directory for the WebClient site on my localhost
在我的web客户端站点的web.config中,我建立了:身份验证模式=“Windows”,身份模拟=“true”
in the webmethod of my webservice that has to call the remote service, I changed to:
engineWSE.Credentials = System.Net.CredentialCache.DefaultCredentials;
When the remote webservice gets invoked with these DefaultCredentials, I get the following error:
System.Web.Services System.Web.Services.Protocols.SoapException: Server was unable to process request.--->
System.Net.WebException:请求失败,HTTP状态为401:未授权。
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse (SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
位于System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object[]参数)
我不确定我是否误解并试图过度简化“模拟”,或者远程Web服务是否以某种方式连接到只接受带有3个参数(即用户名、密码、域)的凭据。