Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Walkthrough: Creating an XML Web Service Using ATL Server

Visual Studio .NET 2003

The following walkthrough describes the process for creating an XML Web service that converts temperatures measured in Fahrenheit to Celsius using C++ and ATL Server.

ATL Server makes it possible for developers to use the Active Template Library to easily implement XML Web services as an ISAPI extension. For more information, see Providing XML Web Services.

During the course of this walkthrough, you will accomplish the following activities:

  • Create an XML Web service using the ATL Server Web Service project template.
  • Implement the XML Web service.
  • Deploy the XML Web service.

To complete the walkthrough, you will need access to a machine that meets the requirements for creating a Web project. For more information, see Creating Web Projects and Visual Studio .NET Software Requirements.

Since XML Web services using ATL Server do not respond to HTTP-GET or HTTP-POST requests, you need to create a client that accesses this XML Web service to explore its functionality. For more information, see Creating XML Web Services.

Creating the XML Web Service Project

Visual Studio provides an ATL Server Web Service project template to help you create XML Web services using ATL Server. For more information, see Creating an ATL Server Project.

To create an ATL Server Web service project

  1. On the File menu, point to New, and then click Project to open the New Project dialog box.
  2. Select the Visual C++ Projects folder, and then click the ATL Server Web Service icon.
  3. In the Name box, type TempConvert4.
  4. Click OK to launch the ATL Server Project Wizard.
  5. In the ATL Server Project Wizard, click Finish to accept the project defaults. For more information, see Creating an ATL Server Project.
    Note   You have the option of creating a combined DLL, which combines the ISAPI functionality with the application code. This option is located on the Project Settings page of the wizard. However, for this walkthrough, you will create separate DLLs.

    The wizard creates a solution, which contains two separate projects: a handler project and an ISAPI extension project.

    Tip   The ATL Server Wizard provides in Solution Explorer a ReadMe.txt file that describes the projects and files generated.
    • You will write the code that provides the functionality for your XML Web service in the handler project, which later becomes your custom handler DLL.
    • You can customize the code used to create the ISAPI extension DLL in the ISAPI extension project. In this project, you will find a ReadMe.txt file that further explains the purpose of each generated file. For this walkthrough, you will not need to customize the ISAPI DLL.

You will create a deployment project as the final step of this walkthrough. For more information, see Creating XML Web Services.

Implementing the XML Web Service

You provide the functionality of your XML Web service with the code you write for the handler class. When your server receives a request for your XML Web service, the ISAPI extension calls this code.

To add an XML Web service method

  1. In Solution Explorer, locate the Header Files folder of the TempConvert4 project, and then double-click TempConvert4.h to open the file for editing.
  2. ITempConvert4Service is the interface definition for the XML Web service. It supports one method, which you will declare as ConvertTemperature. Locate and replace the sample interface definition of ITempConvert4Service with the following:
    __interface ITempConvert4Service
    {
    [id(1)] HRESULT ConvertTemperature(
         [in] double dFahrenheit,
         [out, retval] double* pdCelsius);
    };
    
  3. The CTempConvert4Service class provides the implementation of the XML Web service. You will add a public method to this class and expose that method as part of the XML Web service. In the same file, TempConvert4.h, locate and replace the sample class definition of CTempConvert4Service with the following:
    class CTempConvert4Service :
         public ITempConvert4Service
    {
    public:
         [ soap_method ]
         HRESULT ConvertTemperature(
              /*[in]*/ double dFahrenheit, 
              /*[out, retval]*/ double* pdCelsius)
         {
              if (!pdCelsius)
                   return E_INVALIDARG;
              *pdCelsius = ((dFahrenheit - 32) * 5) / 9;
              return S_OK;
         }
    }; // class CTempConvert4Service
    
    Note   The ATL Server attributes that are located between the interface and class definitions, request_handler and soap_handler, help simplify the task of providing the XML Web service infrastructure. In addition, the soap_method attribute identifies which method to expose as an XML Web service. For more information, see ATL Server Attributes.
  4. Save the solution.
  5. On the Build menu, click Build Solution.

Deploying the XML Web Service

To make your XML Web service available to others, you must deploy it to a Web server that is accessible to the clients you wish to support. To deploy the XML Web service to a server other than the development server, either you can add a Web Setup project or you can copy the required files to the destination server manually.

To deploy the XML Web service using a Web Setup project

  1. On the File menu, point to Add Project, and then click New Project.
  2. Select the Setup and Deployment Projects folder, and then click Web Setup Project.
  3. In the Name box, type TempConvert4WebSetup, and then click OK.
    Note   By default, the installer uses the deployment project name when creating the virtual directory on your deployment server.
  4. In the left pane of the File System Editor, select Web Application Folder. For more information, see File System Editor.
  5. In Solution Explorer, right-click TempConvert4WebSetup, point to Add, and then click Project Output.
  6. In the Add Project Output Group dialog box, select Content Files, Primary output and Debug Symbols. For more information, see Adding and Removing Project Outputs in the File System Editor.
    • The Content Files group consists of the remaining files for the XML Web service, such as TempConvert4.htm and TempConvert4.disco.
    • The Primary output group consists of the project DLL, TempConvert4.dll, and its dependencies.
    • The Debug Symbols group consists of the project PDB file, TempConvert4.pdb.
  7. Click OK.
  8. In Solution Explorer, right-click TempConvert4WebSetup again, point to Add, and then click Project Output.
  9. In the Add Project Output Group dialog box, change the project to TempConvert4Isapi, and then select Primary output and Debug Symbols. For more information, see Adding and Removing Project Outputs in the File System Editor.
    • The Primary output group consists of the project DLL, TempConvert4Isapi.dll, and its dependencies.
    • The Debug Symbols group consists of the project PDB file, TempConvert4Isapi.pdb.
  10. Click OK.
  11. In the left pane of the File System Editor, expand Web Application Folder, then right-click bin and click Delete.
  12. In Solution Explorer, right-click the TempConvert4WebSetup project, and then on the shortcut menu, click Build.

    This creates a Windows Installer file in the local project directory. Execute this file on a Web server to install this XML Web service.

For more information, see Deploying Applications and Components.

Finally, to create a client application that accesses this XML Web service, see one of the following:

See Also

Creating and Accessing XML Web Services Walkthroughs | Visual Studio Walkthroughs | Programming the Web with XML Web Services

Show:
© 2014 Microsoft. All rights reserved.