Building a Test Application


A test application for an ATL Web Service doesn't have to be anything complex or even have a user interface. All you are interested in is testing the Web Service interface to make sure you get the results you are expecting.

A simple managed C++ .NET console application works for testing and is very easy to build. First, use the New, Project menu item to create a new managed C++ application named ATLWebServiceApp. This will build a simple console .NET application.

Adding a Web reference to the new application is the same as it was in the last hour's lesson, except this time the discovery file is a .disco file instead of a .vsdisco file. Select Project, Add Web Reference from the menu bar to display the Add Web Reference dialog. Click the hyperlink to display Web Services that are on your local machine and then select the ATLWebService you just created, as shown in Figure 12.4, and click the Add Reference button to build the proxy class to use in your test application.

Figure 12.4. Adding an ATLWebService Web reference.


Open the ATLWebServiceApp.cpp file, modify the _tmain() function, and then include the WebService.h file, as shown in Listing 12.4.

Listing 12.4 ATLWebServiceApp.cpp The main() Function Modifications to Use the ATLWebServiceService Proxy Object
 1: #include "stdafx.h"  2: #include "WebService.h"  3:  4: #using <mscorlib.dll>  5: #include <tchar.h>  6:  7: using namespace System;  8:  9: // This is the entry point for this application 10: int _tmain(void) 11: { 12:     ATLWebServiceService* pWebService = new ATLWebServiceService; 13: 14:     Console::WriteLine( pWebService->HelloWorld( "You" ) ); 15:     Console::WriteLine( pWebService->CurrentDateTime() ); 16:     Console::WriteLine( pWebService->RectangleArea( 12.5, 10.25 ) ); 17: 18:     return 0; 19: } 

This creates a new instance of the ATLWebServiceService proxy class that points to the ATL Web Service you created. Compiling the application and running it displays the console window shown in Figure 12.5. As you can see, each of the ATL Web Service methods worked and returned the correct results.

Figure 12.5. Console window showing the results of using the ATL Web Service.


As you add additional interfaces to the Web Service, you will have to delete the Web reference and the files it created and then add the Web reference again in order for it to generate the proxy class correctly.


Sams Teach Yourself Visual C++. NET in 24 Hours
Sams Teach Yourself Visual C++.NET in 24 Hours
ISBN: 0672323230
EAN: 2147483647
Year: 2002
Pages: 237

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: