There are a few convenient ways to test a Web Service. You can test a Web Service with the integrated debugger or without the integrated debugger, or you can use the Build and Browse menu. Each method is described in the subsections that follow.
Testing Web Services with the Integrated Debugger
You can set breakpoints and run your XML Web Service as an application. This approach will create a test Web Page, from which you can invoke the Web methods . When the executing test page reaches a breakpoint, control will switch to the Visual Studio .NET integrated debugger, and you can step through and evaluate your Web Service code as you would any other application.
Figure 13.4 shows an example of a test page returned by the .asmx file. Every method tagged with the WebMethod attribute (for example, GetCommission , shown in Figure 13.4) is listed near the top of the service description test page. You can click on the link for a particular method, which will render a test page for that method (Figure 13.5). Enter data values in the text box for each parameter and click the Invoke button. The results are returned as a page containing XML (Figure 13.6).
Figure 13.4. A test page returned by the Web Service when you navigate to the .asmx file.
Figure 13.5. A page for entering input parameter values for Web methods.
Figure 13.6. The results of invoking a Web method, displayed as XML text.
It is worth noting that when you invoke a Web method in your code, all you need to worry about is the value of the response. The XML text is used to move the data across the network, but the actual XML is managed by the technology. From our perspective all we are worried about is the result value, not the XML. Interestingly, the test page's XML response does provide you with an insight into how XML Web Services move data around the Internet.
Testing Web Services without the Integrated Debugger
Suppose you aren't the originator of a Web Service. You will still want to perform testing on the Web Service even if you don't have access to the source code. This kind of testing is referred to as black-box testing (testing from the outside without information about the implementation details of the code).
This second form of testing is accomplished by navigating to the URL that is hosting the Web Service, specifically navigating to the .asmx page. Once you're there, the Web Service DLL will return the same kind of test page shown in the previous subsection. When you have the test page, you can select specific Web methods, enter input values for the parameters, and invoke the Web method. By examining the XML return values you can determine whether the Web Service is providing the correct result.
Testing Web Services with the Build and Browse Menu
As another testing alternative, you can click on the .asmx page in the Solution Explorer in Visual Studio .NET and select Build and Browse from the right-click context menu. The test Web page will be displayed in the browser built into Visual Studio .NET. From this point testing is identical to the previous two processes. Using the Build and Browse menu does not allow you to interact with the integrated debugger; you are performing a black-box test.
After you have tested the Web Services you have implemented, you are ready to deploy those services.