我是靠谱客的博主 美丽背包,最近开发中收集的这篇文章主要介绍调用webservice时报错The request failed with HTTP status 401: Access Denied. 的解决方案。,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Note: This is KB article is taken from MSDN as it is for my own reference.

SYMPTOMS

1.Create a new ASP.NET Web Service by using Visual C# .NET or Visual Basic .NET.
2.Name the project WebServiceTest.
3.By default, Service1.asmx is created.
4.Uncomment the default WebMethod "HelloWorld()".
5.On Build menu, click Build Solution.
6.Turn off Anonymous access to WebServiceTest. To do this, follow these steps:
a. In Control Panel, double-click Administrative Tools.
b. Double-click Internet Information Services.
c. Expand Internet Information Services, and then locate the WebServiceTest virtual directory.
d. Right-click WebServiceTest, and then click Properties.
e. Click the Directory Security tab.
f. Under Anonymous access and authentication control, click Edit.
g. In the Authentication Methods dialog box, click to clear the Anonymous access check box.
h. Click to select the Integrated Windows authentication check box.

Note Verify that only Integrated Windows authentication is selected.
i. Click OK to close the Authentication Methods dialog box.
j. Click OK to close Properties.
7.On the Build menu, click Build Solution.
8.Type the following address in the browser to view the Service1 Web service description:
http://localhost/WebServiceTest/Service1.asmx
9.Test the HelloWorld WebMethod. The WebMethod works as expected.
10.Add a Web Reference to a test ASP.NET Web Application. To do this, follow these steps:
a. Create a new ASP.NET Web Application by using Visual C# .NET or Visual Basic .NET. Name the project WebServiceCaller.
b. By default, WebForm1.aspx is created.
c. In Solution Explorer, right-click References, and then click Add Web Reference.
d. In the Address text box, type the URL for WebServiceTest as follows:
http://localhost/WebServiceTest/Service1.asmx
e. Click Go or press ENTER, and then click Add Reference.
11.In Solution Explorer, right-click WebForm1.aspx, and then click View Code.
12.Append the following code to the Page_Load event:

Visual C# .NET Sample:
// Start an instance of the Web service client-side proxy. localhost.Service1 myProxy = new localhost.Service1(); Response.Write( myProxy.HelloWorld());
Visual Basic .NET Sample:
'Start an instance of the Web service client-side proxy. Dim myProxy As localhost.Service1 = New localhost.Service1() Response.Write(myProxy.HelloWorld())
13.On the Debug menu, click Start, and then view the application in the browser.
14.The error message that is discussed in the "Symptoms" section appears in the browser.
15.To resolve this problem, assign DefaultCredentials to the Credentials property of the Web service client-side proxy. To do this, insert the following code before the line "Response.Write( myProxy.HelloWorld())":

Visual C# .NET Sample:
myProxy.Credentials= System.Net.CredentialCache.DefaultCredentials;
Visual Basic .NET Sample:
myProxy.Credentials = System.Net.CredentialCache.DefaultCredentials
16.

Repeat step 13

最后

以上就是美丽背包为你收集整理的调用webservice时报错The request failed with HTTP status 401: Access Denied. 的解决方案。的全部内容,希望文章能够帮你解决调用webservice时报错The request failed with HTTP status 401: Access Denied. 的解决方案。所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部