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 |