Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
732 Project 7 CREATING WEB SERVICES
the process of actually installing the application, but the DLL created will be heavier and the performance will diminish.
4. Click on Server Options to display the page shown in Figure 24-4.
FIGURE 24-4 The Visual C++ ATL Server Project Wizard – Server Options page
This page lists a few important additional support features that you can add to your application at the click of a check box.
5.Click on Application Options which displays the Application Options page shown in Figure 24-5.
This page contains a check box named Create as Web Service. By default, this option is selected if you select the ATL Web service project type. On the other hand, if you select ATL Server application as the project type, you need to select this check box to convert the application into a Web service.
After the project has been created, you will find that the IDE has created a HelloWorld Web service. The project has a host of files created. Next, you will browse through the list of files appearing in the Solution Explorer window shown in Figure 24-6.
734 Project 7 CREATING WEB SERVICES
Two projects are created in the solution:
ExRateWS
ExRateWSIsapi
The ISAPI extension DLL project, ExRateWSIsapi, doesn’t require any modifications. So, let me concentrate on explaining the ExRateWS project. Some of the files that are part of the project, ExRateWS, are listed here:
ExRateWS.cpp. Contains the method declarations necessary for the DLL, such as DllMain.
ExRateWS.h. Contains the code required for implementing the default Web service.
ExRateWS.Disco. Contains the data required for the dynamic discovery of the Web service. In the previous chapter, you saw that the IDE created a DISCO file. The DISCO file is an earlier version of the VSDISCO file.
ExRateWS.htm. Contains the path to the WSDL file for the Web service. This file describes the operations available in the default Web service (i.e., HelloWorld). However, this piece of information is hard coded and doesn’t change when you add more operations or delete the default operation. So, do not get confused if you connect to this page after it has been deployed and you see a listing for HelloWorld.
Among these files, the ExRateWS.h file hosts the functionality of the Web service:
// ExRateWS.h : Defines the ATL Server request handler class
//
#pragma once
namespace ExRateWSService
{
//all struct, enum, and typedefs for your webservice should go inside the //namespace
//IExRateWSService - Web service interface declaration
//
[
uuid(“D935E244-26D2-4DCC-9FC7-FB0DF6E61E94”),
CREATING A WEB SERVICE USING ATL SERVER |
Chapter 24 |
735 |
|
|
|
|
|
object
]
__interface IExRateWSService
{
//HelloWorld is a sample ATL Server web service method. It shows how to
//declare a web service method and its in-parameters and out-parameters [id(1)] HRESULT HelloWorld([in] BSTR bstrInput, [out, retval] BSTR *bstrOutput);
//TODO: Add additional web service methods here
};
// ExRateWSService - web service implementation
//
[
request_handler(name=”Default”, sdl=”GenExRateWSWSDL”), soap_handler(
name=”ExRateWSService”,
namespace=”urn:ExRateWSService”,
protocol=”soap”
)
]
class CExRateWSService :
public IExRateWSService
{
public:
//This is a sample web service method that shows how to use the
//soap_method attribute to expose a method as a web method
[ soap_method ]
HRESULT HelloWorld(/*[in]*/ BSTR bstrInput, /*[out, retval]*/ BSTR *bstrOutput)
{
CComBSTR bstrOut(L”Hello “); bstrOut += bstrInput; bstrOut += L”!”;
*bstrOutput = bstrOut.Detach();
738Project 7 CREATING WEB SERVICES
2.In the dialog box, select ATL OLEDB Consumer.
3.Click on the Open button. This opens the ATL OLEDB Consumer Wizard, shown in Figure 24-8.
FIGURE 24-8 ATL OLEDB Consumer Wizard
4.Click on the Data Source button. This opens the Data Link Properties dialog box, shown in Figure 24-9.
5.In the displayed list of OLEDB providers, select Microsoft OLEDB Provider for SQL Server.
6.Click on the Next button. On the Connection tab of the Data Link Properties dialog box, you need to enter the details for connecting to the SQL Server, as shown in Figure 24-10.
7.Select the name of your SQL server and also the authentication type as appropriate to your local SQL server installation. Also select the name of the database you have created.
8.Click on the Test Connection button to validate the connection string. If the testing is successful, then click on the OK button. This will open the Select Database Object dialog box shown in Figure 24-11.
