调用Web服务:请求因HTTP状态401失败:Unauthorized
2014-05-06 13:16
661 查看
“/CallService”应用程序中的服务器错误。
--------------------------------------------------------------------------------
请求因 HTTP 状态 401 失败: Unauthorized。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Net.WebException: 请求因 HTTP 状态 401 失败: Unauthorized。
源错误:
行 81: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld",
RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 82: public string HelloWorld() {
行 83: object[] results = this.Invoke("HelloWorld", new object[0]);
行 84: return ((string)(results[0]));
行 85: }
源文件: D:\Cofco\CofcoMeeting\VSProjects\Cofco.Meeting\Cofco.Meeting.CallService\Web References\ApproveService\Reference.cs
行: 83
堆栈跟踪:
[WebException: 请求因 HTTP 状态 401 失败: Unauthorized。]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response,
Stream responseStream, Boolean asyncCall) +533199
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
Cofco.Meeting.CallService.ApproveService.Service1.HelloWorld() in
D:\Cofco\CofcoMeeting\VSProjects\Cofco.Meeting\Cofco.Meeting.CallService\Web References\ApproveService\Reference.cs:83
Cofco.Meeting.CallService._Default.btnHello_Click(Object sender, EventArgs e) in
D:\Cofco\CofcoMeeting\VSProjects\Cofco.Meeting\Cofco.Meeting.CallService\Default.aspx.cs:25
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42
========================================================================================================
解决方案1
设置你的IIS里面的WEB SERVICE以勾选匿名访问
单击开始,指向管理工具,然后单击Internet 信息服务 (IIS)。
展开你的IIS服务器,右键单击提供服务的WebService文件,然后单击属性。
在Web 站点属性 对话框中,单击目录安全性 选项卡。
在“身份验证和访问控制”下,单击编辑。
单击“启用匿名访问”复选框,将其选中。
备注:“用户名”框中的用户帐户只用于通过 Windows guest 帐户进行匿名访问。
默认情况下,服务器会创建并使用帐户 IUSR_computername。匿名用户帐户密码仅在Windows 中使用;匿名用户不使用用户名和密码登录。
在“已验证身份的访问”下,单击“集成的 Windows 身份验证”复选框,将其选中。
单击确定 两次。
解决方案2
ApproveService.Service1 ws1 = new Cofco.Meeting.CallService.ApproveService.Service1();
string str = String.Empty;
ws1.Url = "http://localhost/ApproveService/Service1.asmx";
ws1.PreAuthenticate = true;s1.Credentials = System.Net.CredentialCache.DefaultCredentials;//这两句在NET 1.1或2.0下同样有效
ws1.UseDefaultCredentials = true;//NET 2.0使用
str = ws1.HelloWorld();
lbMsg.Text = str;
--------------------------------------------------------------------------------
请求因 HTTP 状态 401 失败: Unauthorized。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Net.WebException: 请求因 HTTP 状态 401 失败: Unauthorized。
源错误:
行 81: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/HelloWorld",
RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 82: public string HelloWorld() {
行 83: object[] results = this.Invoke("HelloWorld", new object[0]);
行 84: return ((string)(results[0]));
行 85: }
源文件: D:\Cofco\CofcoMeeting\VSProjects\Cofco.Meeting\Cofco.Meeting.CallService\Web References\ApproveService\Reference.cs
行: 83
堆栈跟踪:
[WebException: 请求因 HTTP 状态 401 失败: Unauthorized。]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response,
Stream responseStream, Boolean asyncCall) +533199
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
Cofco.Meeting.CallService.ApproveService.Service1.HelloWorld() in
D:\Cofco\CofcoMeeting\VSProjects\Cofco.Meeting\Cofco.Meeting.CallService\Web References\ApproveService\Reference.cs:83
Cofco.Meeting.CallService._Default.btnHello_Click(Object sender, EventArgs e) in
D:\Cofco\CofcoMeeting\VSProjects\Cofco.Meeting\Cofco.Meeting.CallService\Default.aspx.cs:25
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42
========================================================================================================
解决方案1
设置你的IIS里面的WEB SERVICE以勾选匿名访问
单击开始,指向管理工具,然后单击Internet 信息服务 (IIS)。
展开你的IIS服务器,右键单击提供服务的WebService文件,然后单击属性。
在Web 站点属性 对话框中,单击目录安全性 选项卡。
在“身份验证和访问控制”下,单击编辑。
单击“启用匿名访问”复选框,将其选中。
备注:“用户名”框中的用户帐户只用于通过 Windows guest 帐户进行匿名访问。
默认情况下,服务器会创建并使用帐户 IUSR_computername。匿名用户帐户密码仅在Windows 中使用;匿名用户不使用用户名和密码登录。
在“已验证身份的访问”下,单击“集成的 Windows 身份验证”复选框,将其选中。
单击确定 两次。
解决方案2
ApproveService.Service1 ws1 = new Cofco.Meeting.CallService.ApproveService.Service1();
string str = String.Empty;
ws1.Url = "http://localhost/ApproveService/Service1.asmx";
ws1.PreAuthenticate = true;s1.Credentials = System.Net.CredentialCache.DefaultCredentials;//这两句在NET 1.1或2.0下同样有效
ws1.UseDefaultCredentials = true;//NET 2.0使用
str = ws1.HelloWorld();
lbMsg.Text = str;
相关文章推荐
- 调用Web服务:请求因HTTP状态401失败:Unauthorized
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- 调用webserver时出现:请求因 HTTP 状态 401 失败: Unauthorized。
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- 异常:"System.Net.WebException: 请求因 HTTP 状态 401 失败:Unauthorized。"
- 代码调用服务--请求因 HTTP 状态 401 失败:Access Denied。(downmoon原创)
- 异常:"System.Net.WebException: 请求因 HTTP 状态 401 失败:Unauthorized。"
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- 代码调用服务--请求因 HTTP 状态 401 失败:Access Denied。(downmoon原创)
- 代码调用服务--请求因 HTTP 状态 401 失败:Access Denied。(downmoon原创)
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- C# 调WebService 报请求因 HTTP 状态 401 失败: Unauthorized 的解决
- WebService请求因 HTTP 状态 401 失败: Unauthorized。
- SSRS:部署错误之“请求因 HTTP 状态 401 失败: Unauthorized。”
- 请求因 HTTP 状态 401 失败:Unauthorized。
- 请求因 HTTP 状态 401 失败:Unauthorized
- 请求因 HTTP 状态 401 失败:Unauthorized
- 请求因 HTTP 状态 401 失败:Unauthorized。
- 解决 请求因 HTTP 状态 401 失败: Unauthorized。
- SSRS:部署错误之“请求因 HTTP 状态 401 失败: Unauthorized。”