Export (0) Print
Expand All
Expand Minimize

How to Create and Deploy XML Web Services Using Visual Basic 6.0 and Office XP

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
 

Frank C. Rice
Microsoft Corporation

May 2002

Applies to:
     Microsoft® Visual Basic® 6.0 with Service Pack 5
     Microsoft Access 2002
     Microsoft Office XP Web Services Toolkit
     SOAP Toolkit 2.0

Summary: Learn how to create, deploy, and use a sample XML Web service created with Microsoft Visual Basic 6.0 (with Service Pack 5) and the SOAP Toolkit 2.0. A Microsoft Access 2002 form is used to access the XML Web service. (19 printed pages)

Download SoapToolkit20.EXE.




Contents

Introduction
XML Web Services Overview
XML Web Services in Visual Basic 6.0
Creating the XML Web Service
Creating the Client Application
Testing the XML Web Service
Conclusion

Introduction

XML Web services provide a way for applications to exchange data and processing capability. Typically, an XML Web service is a dynamic-link library (DLL) that resides on a Web server and whose methods can be called over the Internet. In this scenario, a client application communicates with the XML Web service by sending and receiving SOAP messages over Hyper Text Transfer Protocol (HTTP).

In this article, we'll demonstrate how to create, deploy, and access an XML Web service. First, we'll set up Internet Information Server (IIS) on the Web server which will host the XML Web service.

Note   IIS 4.0 is compatible with Microsoft® Windows NT® 4.0 Server. IIS 5.0 is compatible with and installed by default with Microsoft Windows® 2000 Server.

Then, using Microsoft Visual Basic® 6.0, we'll create a simple ActiveX® DLL as a sample XML Web service which accepts the two-digit name of a U.S. state and returns the state's full name, its capital, the date the state was admitted to the union, and its order of admittance. Next, we'll use the SOAP Toolkit 2.0 WSDL/WSML Generator to create the Web Services Description Language (WSDL) and Web Services Meta Language (WSML) files. And finally, we'll create a Microsoft Access 2002 form to use as our client application and then access the XML Web service and display the results.

XML Web Services Overview

So what's involved in creating and using an XML Web service? Typically, a person might begin by navigating to a Web site hosting an XML Web service registry, such as the Universal Description, Discovery, and Integration (UDDI) registry service, to see what XML Web services are available. The registry service would provide information about the different XML Web services available such as the name of the company hosting the XML Web service, the universal resource locator (URL) to the company's Web site, and the location of the WSDL file, which the user uses to determine the details of the XML Web service.

A developer would then use the information gleaned from the WSDL file to develop a client application to access the XML Web service and process the results. The developer would first set a reference to the Microsoft SOAP Library (mssoap1.dll) which can be obtained by installing the SOAP Toolkit 2.0.

Note   The Microsoft SOAP Toolkit 2.0 SP2 can be downloaded from MSDN.

The Microsoft SOAP Library contains client-side (and server-side) components that allow an application to invoke XML Web service methods. The developer would then set a Web reference (using the Web Service References Tool) to the WSDL file.

Note   The Web Service References Tool is available in the Office XP Web Services Toolkit which can be downloaded from MSDN.

The Web Service References Tool creates a proxy class (a local representation of the XML Web service in the client application) which makes it easy to communicate with the XML Web service by using HTTP. This communication would consist of SOAP requests from the client application and SOAP responses from the XML Web service. The server implementing the XML Web service would use a "listener" (code that resides in the WSDL file or an Active Server Pages (ASP) file that implements a handler) to receive and parse the SOAP request. Once the listener detected a SOAP request from the client application, it would parse the request, invoke the XML Web service method passing in any parameters, and then receive the results of the method calls. The listener would then wrap the response in another SOAP message and send the response to the client application where the results are parsed and processed by the client-side component.

So far, we have looked at the client-side of consuming XML Web services. In order to create and implement an XML Web service on a Web server, you need the following:

  • A DLL that contains the function (methods) that you want to make available as the XML Web service. Typically, this is a project created in Microsoft Visual Basic 6.0.
  • A method to tell clients interested in using the XML Web service what functionality is provided, the names of the methods, the input/output parameters used, and other information relevant to the XML Web service. A WSDL file provides this information.
  • A file that maps the method calls in the object implementing the XML Web service (for example, a Common Object Model (COM) object) to the names of the operations implemented by the XML Web service. A WSML file provides this information. This file is specific to the SOAP Toolkit.
    Note   As we'll see shortly, the SOAP Toolkit contains a utility called the WSDL/WSML Generator that generates the WSDL and WSML files for you, relieving you of the tedious process of manually creating such files.
  • (Optional) Register the XML Web service with a registry service such as a UDDI registry. This service provides a central location that users can use to locate the various XML Web services available on the Web.

In order to use an XML Web service, all you need to do is create the client application that accesses the XML Web service using the information contained in the WSDL file and ensure that the Microsoft SOAP Library is installed on each client computer. Depending on the development environment you use to create the client will determine what, if any, additional tools you might need.

XML Web Services in Visual Basic 6.0

Using the SOAP Toolkit with Visual Basic 6.0 simplifies the task of creating and deploying XML Web services. The SOAP Toolkit provides a server-side component (the SoapServer object) which is used to expose the methods of your XML Web service. After creating the class that provides the functionality of your XML Web service in Visual Basic 6.0, the SOAP Toolkit also contains the WSDL/WSML Generator utility which examines the class and creates the WSDL and WSML files. The utility also adds code to the WSDL file, which designates it as a SOAP listener.

On the client-side, the SOAP toolkit provides another component (the SoapClient object) that can be used to access the methods of the XML Web service. In addition, the Office XP Web Services Toolkit provides the Web Service References Tool, which is used to create a proxy class that provides access, through the SoapClient object, to the methods that make up the XML Web service.

Now let's create the XML Web service.

Creating the XML Web Service

To create and deploy the XML Web service, you'll need a Web server such as Microsoft Windows® 2000 Server running IIS. You'll also need to set up a virtual root (also called a virtual directory) on the Web server where you can store the XML Web service files that are created.

Setting Up Internet Information Server

Add a folder to the Web server. You can use an existing folder or create a new folder on the server. For this sample, I'd suggest creating a new folder (for example, C:\StatesInfo).

Next, set up the virtual root in IIS. In the Control Panel, double-click Administrative Tools, and then double-click Internet Services Manager to display the Internet Information Services console.

  1. In the left-hand pane, expand the node containing the name of your Web server, right-click the Default Web Site node, point to New, and then click Virtual Directory. This opens the Virtual Directory wizard.
  2. In the Welcome to the Virtual Directory Creation Wizard screen, click Next.
  3. In the Virtual Directory Alias screen, type StatesInfo, and then click Next.
  4. In the Web Site Content Directory screen, type the path to the folder you created in step 1 and click Next.
  5. In the Access Permissions screen, select the Read and Execute check boxes and click Next. Click Finish.

Creating the ActiveX DLL

Now we'll create a new Visual Basic ActiveX DLL project named StatesInfo and a class module named clsStatesInformation with the GetStateInfo method.

  1. Start Visual Basic 6.0.
  2. In the New Project dialog box, select ActiveX DLL and click Open.
  3. In the Project Explorer, click Project 1. In the property sheet, change the project name to StatesInfo.
  4. Moving back to the Project Explorer, click Class 1. In the property sheet, change the class name to clsStatesInformation.
  5. In the code window, insert the following function. This will be the method for your XML Web service. Note   This code has been "broken" to conform to MSDN Web page layout:
    Public Function GetStateInfo(ByVal strAbbreviatedName As String)
         As String
        'Purpose: This procedure is used to simulate an
        '         XML Web service. The procedure accepts
        '         the two-digit name for a state and
        '         returns information about that state.
        'Accepts: strAbbreviatedName - the two-digit state
        '                             name.
        'Returns: Information about the state including
        '         its full name, capital, date admitted
        '         to the union, and order of admission.
        '
        
        Select Case UCase(Trim(strAbbreviatedName))
            Case "AL"
                GetStateInfo = "Name: Alabama " & _
                               "Capital: Montgomery " & _
                               "Admitted: December 14, 1819 " & _
                               "Order: 22"
            Case "AK"
                GetStateInfo = "Name: Alaska " & _
                               "Capital: Juneau " & _
                               "Admitted: January 3, 1959 " & _
                               "Order: 49"
            Case "AZ"
                GetStateInfo = "Name: Arizona " & _
                               "Capital: Phoenix " & _
                               "Admitted: February 14, 1912 " & _
                               "Order: 48"
            Case "AR"
                GetStateInfo = "Name: Arkansas " & _
                               "Capital: Little_Rock " & _
                               "Admitted: June 15, 1836 " & _
                               "Order: 25"
            Case "CA"
                GetStateInfo = "Name: California " & _
                               "Capital: Sacramento " & _
                               "Admitted: September 9, 1850 " & _
                               "Order: 31"
            Case "CO"
                GetStateInfo = "Name: Colorado " & _
                               "Capital: Denver " & _
                               "Admitted: August 1, 1876 " & _
                               "Order: 38"
            Case "CT"
                GetStateInfo = "Name: Connecticut " & _
                               "Capital: Hartford " & _
                               "Admitted: January 9, 1788 " & _
                               "Order: 5"
            Case "DC"
                GetStateInfo = "Name: District_of_Columbia " & _
                               "Capital: Not_Applicable " & _
                               "Admitted: N/A " & _
                               "Order: N/A"
            Case "DE"
                GetStateInfo = "Name: Delaware " & _
                               "Capital: Dover " & _
                               "Admitted: December 7, 1787 " & _
                               "Order: 1"
            Case "FL"
                GetStateInfo = "Name: Florida " & _
                               "Capital: Tallahassee " & _
                               "Admitted: March 3, 1845 " & _
                               "Order: 27"
            Case "GA"
                GetStateInfo = "Name: Georgia " & _
                               "Capital: Atlanta " & _
                               "Admitted: January 2, 1788 " & _
                               "Order: 4"
            Case "HI"
                GetStateInfo = "Name: Hawaii " & _
                               "Capital: Honolulu " & _
                               "Admitted: August 21, 1959 " & _
                               "Order: 50"
            Case "ID"
                GetStateInfo = "Name: Idaho " & _
                               "Capital: Boise " & _
                               "Admitted: July 3, 1890 " & _
                               "Order: 43"
            Case "IL"
                GetStateInfo = "Name: Illinois " & _
                               "Capital: Springfield " & _
                               "Admitted: Decemer 3, 1818 " & _
                               "Order: 21"
            Case "IN"
                GetStateInfo = "Name: Indiana " & _
                               "Capital: Indianapolis " & _
                               "Admitted: December 11, 1816 " & _
                               "Order: 19"
            Case "IA"
                GetStateInfo = "Name: Iowa " & _
                               "Capital: Des_Moines " & _
                               "Admitted: December 28, 1846 " & _
                               "Order: 29"
            Case "KS"
                GetStateInfo = "Name: Kansas " & _
                               "Capital: Topeka " & _
                               "Admitted: January 29, 1861 " & _
                               "Order: 34"
            Case "KY"
                GetStateInfo = "Name: Kentucky " & _
                               "Capital: Frankfort " & _
                               "Admitted: June 1, 1792 " & _
                               "Order: 15"
            Case "LA"
                GetStateInfo = "Name: Louisiana " & _
                               "Capital: Baton_Rouge " & _
                               "Admitted: April 30, 1812 " & _
                               "Order: 18"
            Case "ME"
                GetStateInfo = "Name: Maine " & _
                               "Capital: Augusta " & _
                               "Admitted: March 15, 1820 " & _
                               "Order: 23"
            Case "MD"
                GetStateInfo = "Name: Maryland " & _
                               "Capital: Annapolis " & _
                               "Admitted: April 28, 1788 " & _
                               "Order: 7"
            Case "MA"
                GetStateInfo = "Name: Massachesetts " & _
                               "Capital: Boston " & _
                               "Admitted: February 6, 1788 " & _
                               "Order: 6"
            Case "MI"
                GetStateInfo = "Name: Michigan " & _
                               "Capital: Lansing " & _
                               "Admitted: Jan 26, 1837 " & _
                               "Order: 26"
            Case "MN"
                GetStateInfo = "Name: Minnesota " & _
                               "Capital: St._Paul " & _
                               "Admitted: May 11, 1858 " & _
                               "Order: 32"
            Case "MS"
                GetStateInfo = "Name: Mississippi " & _
                               "Capital: Jackson " & _
                               "Admitted: December 10, 1817 " & _
                               "Order: 20"
            Case "MO"
                GetStateInfo = "Name: Missouri " & _
                               "Capital: Jefferson_City " & _
                               "Admitted: August 10, 1821 " & _
                               "Order: 24"
            Case "MT"
                GetStateInfo = "Name: Montana " & _
                               "Capital: Helena " & _
                               "Admitted: November 8, 1889 " & _
                               "Order: 41"
            Case "NE"
                GetStateInfo = "Name: Nebraska " & _
                               "Capital: Lincoln " & _
                               "Admitted: March 1, 1867 " & _
                               "Order: 37"
            Case "NV"
                GetStateInfo = "Name: Nevada " & _
                               "Capital: Carson_City " & _
                               "Admitted: October 31, 1864 " & _
                               "Order: 36"
            Case "NH"
                GetStateInfo = "Name: New_Hampshire " & _
                               "Capital: Concord " & _
                               "Admitted: June 21, 1788 " & _
                               "Order: 9"
            Case "NJ"
                GetStateInfo = "Name: New_Jersey " & _
                               "Capital: Trenton " & _
                               "Admitted: December 18, 1787 " & _
                               "Order: 3"
            Case "NM"
                GetStateInfo = "Name: New_Mexico " & _
                               "Capital: Santa_Fe " & _
                               "Admitted: January 6, 1912 " & _
                               "Order: 47"
            Case "NY"
                GetStateInfo = "Name: New_York " & _
                               "Capital: Albany " & _
                               "Admitted: July 26, 1788 " & _
                               "Order: 11"
            Case "NC"
                GetStateInfo = "Name: North_Carolina " & _
                               "Capital: Raleigh " & _
                               "Admitted: November 21, 1789 " & _
                               "Order: 12"
            Case "ND"
                GetStateInfo = "Name: North_Dakota " & _
                               "Capital: Bismarck " & _
                               "Admitted: November 2, 1889 " & _
                               "Order: 39"
            Case "OH"
                GetStateInfo = "Name: Ohio " & _
                               "Capital: Columbus " & _
                               "Admitted: March 1, 1803 " & _
                               "Order: 17"
            Case "OK"
                GetStateInfo = "Name: Oklahoma " & _
                               "Capital: Oklahoma_City " & _
                               "Admitted: November 16, 1907 " & _
                               "Order: 46"
            Case "OR"
                GetStateInfo = "Name: Oregon " & _
                               "Capital: Salem " & _
                               "Admitted: February 14, 1859 " & _
                               "Order: 33"
            Case "PA"
                GetStateInfo = "Name: Pennsylvania " & _
                               "Capital: Harrisburg " & _
                               "Admitted: December 12, 1787 " & _
                               "Order: 2"
            Case "RI"
                GetStateInfo = "Name: Rhode_Island " & _
                               "Capital: Providence " & _
                               "Admitted: May 29, 1790 " & _
                               "Order: 13"
            Case "SC"
                GetStateInfo = "Name: South_Carolina " & _
                               "Capital: Columbia " & _
                               "Admitted: May 23, 1788 " & _
                               "Order: 8"
            Case "SD"
                GetStateInfo = "Name: South_Dakota " & _
                               "Capital: Pierre " & _
                               "Admitted: November 2, 1889 " & _
                               "Order: 40"
            Case "TN"
                GetStateInfo = "Name: Tennessee " & _
                               "Capital: Nashville " & _
                               "Admitted: June 1, 1796 " & _
                               "Order: 16"
            Case "TX"
                GetStateInfo = "Name: Texas " & _
                               "Capital: Austin " & _
                               "Admitted: December 28, 1846 " & _
                               "Order: 29"
            Case "UT"
                GetStateInfo = "Name: Utah " & _
                               "Capital: Salt_Lake_City " & _
                               "Admitted: January 4, 1896 " & _
                               "Order: 45"
            Case "VT"
                GetStateInfo = "Name: Vermont " & _
                               "Capital: Montpelier " & _
                               "Admitted: March 4, 1791 " & _
                               "Order: 14"
            Case "VA"
                GetStateInfo = "Name: Virginia " & _
                               "Capital: Richmond " & _
                               "Admitted: June 25, 1788 " & _
                               "Order: 10"
            Case "WA"
                GetStateInfo = "Name: Washington " & _
                               "Capital: Olympia " & _
                               "Admitted: November 11, 1889 " & _
                               "Order: 42"
            Case "WV"
                GetStateInfo = "Name: West_Virginia " & _
                               "Capital: Charleston " & _
                               "Admitted: June 20, 1863 " & _
                               "Order: 35"
            Case "WI"
                GetStateInfo = "Name: Wisconsin " & _
                               "Capital: Madison " & _
                               "Admitted: May 29, 1848 " & _
                               "Order: 30"
            Case "WY"
                GetStateInfo = "Name: Wyoming " & _
                               "Capital: Cheyenne " & _
                               "Admitted: July 10, 1890 " & _
                               "Order: 44"
            Case Else
                GetStateInfo = "The value you entered is not a valid " & _
                               "state abbreviation. Please enter a " & _
                               "valid two-digit abbreviation."
        End Select
    End Function
    
    
  6. Now create the DLL. On the File menu, select Make StatesInfo.dll. In the Make Project dialog box, type in a path for the file (use the folder created in step 1 of the "Setting Up Internet Information Server" section above) and click OK.
    Note   If you created this DLL on a computer other than the server running IIS, you will need to copy it from that computer to the Web server hosting the XML Web service (use the folder created in step 1 of the "Setting Up Internet Information Server" section above) and register it on the server. On the Web server, click the Start button, point to Run, and type in the following (replace
    <path>
    with the absolute path where you saved your DLL):
          regsvr32 <path>\StatesInfo.dll
    
    

Generating the WSDL and WSML Files

Now generate the WSDL and WSML files using the SOAP Toolkit's WSDL/WSML Generator wizard.

  1. On the Start menu, point to Programs, Microsoft SOAP Toolkit, and then click WSDL Generator to start the WSDL Generator wizard.
  2. On the Welcome to the SOAP Toolkit 2.0 Wizard screen, click Next.
  3. In the What would you like to name your service? text box, type the name of your XML Web service. For example, StatesInformation. This will be the name of the WSDL and WSML files.
  4. Click Select COM Object, select the DLL (StatesInfo.dll), and then click Open.
  5. Click Next.
  6. Expand the clsStatesInformation node and select the GetStateInfo check box. All of the check boxes are then selected. This is the method name that will appear in the WSDL and WSML files. Click Next.

    In the URI box, type the URL of the folder which will contain the WSDL and WSML files. For example, if you are hosting the XML Web service on your local machine, use http://localhost/StatesInfo where StatesInfo is the virtual root. Do not include the files in the URL; the wizard will add the files to this location.

  7. Select ISAPI as the listener type.
  8. Select the XSD Schema namespace (2001 is the default). For this sample, use the default 2001 namespace. Click Next.
  9. Select the character set for the WSDL file (UTF-8 or UTF-16). For this sample, use the default UTF-8.
  10. In the Where would you like to store the new files? text box, type the location where you want to save the resulting WSDL and WSML files (use the path created in step 1). Click Next.
  11. At this point, the generator tool creates and saves the files. Click Finish to exit.

You have now created all of the server-side files necessary for your XML Web service. Now we'll create the client application.

Creating the Client Application

We will now create a form in Access 2002 which will be used to call the XML Web service and display the results. Figure 1 shows what the form should look like when completed.

Aa140016.odc_websvsvb601(en-us,office.10).gif

Figure 1. The frmGetStateInfo form

To run this application within Access, you will need to set a reference to the Microsoft SOAP Type Library (mssoap1.dll) from the References dialog box (Tools menu).

  1. Start Access 2002.
  2. In the Database window, click Forms under Objects, and then click New to display the New Form dialog box.
  3. In the New Form dialog box, select Design View and click OK.
  4. Click the label for the txtAbbrevName control and change the Caption property to Enter the two-digit abbreviation for a state and click Get Information.
  5. In the property sheet, change the text in the Caption property to Gets Data from an XML Web Service.
  6. From the Toolbox (View menu), drag a Text Box control onto the form. In the property sheet, change the Name property to txtAbbrevName.
  7. In the View menu, click Properties to open the property sheet for the form.
  8. From the Toolbox, drag a Command Button control onto the form. Click Cancel in the Command Button Wizard screen. In the property sheet, change the name of the control to cmdGetInfo.
  9. Change the Caption property of the cmdGetInfo control to Get Information. In the property sheet, click the Event tab, click the On Click event, and then click the build button (with the ellipses. . .).
  10. In the Visual Basic Editor, you will first need to need to add a Web reference to a URL that contains a description of the method available in your XML Web service. On the Tools menu, click Web Service References.
    Note   The Web Service References Tool is contained in the Office XP Web Services Toolkit which is available from MSDN.
  11. In the Web Service References dialog box, click Web Service URL. In the URL box, type the URL to your XML Web service description file and click Search. For the XML Web service in this demonstration, that would be http://localhost/StatesInformationWS/StatesInformation.asmx?wsdl.

    Aa140016.odc_websvsvb602(en-us,office.10).gif

    Figure 2. The Web Service References dialog box

  12. In the Search Results box, select StatesInformation. See Figure 4. Click the + to expand the node. You can test the method by selecting GetStateInfo and clicking Test.
  13. Click Add. The clsws_StatesInformation class is added under the Class Modules folder. This class acts as a proxy which provides interfaces for the XML Web service and provides a local representation of the XML Web service.
  14. Double-click the clsws_StatesInformation class. As you scroll through the code, you will notice that there are a number of event procedures such as Class_Initialize, Class_Terminate, which were created automatically by the Web Service References tool. You will also notice the wsm_GetStateInfo function, which is used to call the GetStateInfo method of the StatesInformation class of the XML Web service you created.
  15. Double-click the form module. Add the following code to the cmdGetInfo_Click event procedure:
        ' Purpose: The procedure is used to test the
        '          sample StatesInformation XML Web
        '          service by calling the wsm_getStateInfo
        '          function of the clsws_StatesInformation
        '          proxy class. This method then calls the
        '          XML Web service sending a two-digit state
        '          abbreviation and displays the return 
        '          information.
        '
        ' Returns: The state full name, the state capital,
        '          the date the state was admitted to the
        '          the union, and the order it was admitted.
        '
        Dim clsStatesWS As clsws_StatesInformation
        Dim strUserInfo As String
        Dim strReturn As String
        Dim strName As String
        Dim strCapital As String
        Dim strDate As String
        Dim strOrder As String
        Dim intStart As Integer
        Dim intEnd As Integer
        Dim intLength As Integer
        
        On Error GoTo cmdGetInfo_Click_Err
        
        ' Create a reference to the clsws_StatesInformation class.
        Set clsStatesWS = New clsws_StatesInformation
        
        Me!txtAbbrevName.SetFocus
        strUserInfo = Me!txtAbbrevName.Text
        
        ' Call the wsm_GetStateInfo method.
        strReturn = Trim(clsStatesWS.wsm_GetStateInfo(strUserInfo))
        
        ' Check to see if the state information was returned.
        If Left(strReturn, 4) <> "Name" Then
            MsgBox strReturn, , "Not a valid Entry"
            GoTo cmdGetInfo_Click_End
        End If
        
        ' Parse the return string.
        
        ' Get the Name field.
        ' Find the first :.
        intStart = InStr(1, strReturn, ":") + 2
        ' Find the first blank after the name.
        intEnd = (InStr(intStart, strReturn, " "))
        ' The number of characters to grab.
        intLength = intEnd - intStart
        strName = Mid(strReturn, intStart, intLength)
        
        ' Check to see if there is an underscore between
        ' the words and remove it before display.
        If InStr(1, strName, "_") <> 0 Then
            strName = Replace(strName, "_", " ")
        End If
        
        Me!txtName.SetFocus
        Me!txtName.Text = strName
           
        ' Get the Capital field.
        ' Find the second : by starting at the end of
        ' the name field.
        intStart = InStr(intEnd, strReturn, ":") + 2
        ' Find the blank after the date.
        intEnd = (InStr(intStart, strReturn, " "))
        ' The number of characters to grab.
        intLength = intEnd - intStart
        strCapital = Mid(strReturn, intStart, intLength)
        
        ' Check to see if there is an underscore between
        ' the words and remove it before display.
        If InStr(1, strCapital, "_") <> 0 Then
            strCapital = Replace(strCapital, "_", " ")
        End If
        
        Me!txtCapital.SetFocus
        Me!txtCapital.Text = strCapital
        
        ' Get the date field.
        intStart = InStr(intEnd, strReturn, ":") + 2
        ' Find the comma after the day and add 6 for
        ' the year.
        intEnd = (InStr(intStart, strReturn, ",") + 6)
        ' The number of characters to grab.
        intLength = intEnd - intStart
        strDate = Mid(strReturn, intStart, intLength)
        
        Me!txtDate.SetFocus
        Me!txtDate.Text = strDate
        
        ' And finally, get the order that the state was
        ' admitted to the union.
        strOrder = Trim(Right(strReturn, 2))
        
        Me!txtOrder.SetFocus
        Me!txtOrder.Text = strOrder
        
        Me!txtAbbrevName.SetFocus
            
    cmdGetInfo_Click_End:
        Exit Sub
    cmdGetInfo_Click_Err:
        MsgBox Err.Number & ":" & Err.Description
        GoTo cmdGetInfo_Click_End
    
    
  16. Close the Visual Basic Editor.
  17. From the Toolbox, add four additional Text Box controls to the form, positioning them under the Get Information button.
  18. Double-click the first Text Box control to bring up the property sheet. Change the name of the control to txtName.
  19. Click the label for the control and change the Caption property to Name:.
  20. Repeat steps 18 and 19 for the three remaining controls, changing the following properties:
    Name property for the Text Box controlsCaption property for the associated labels
    txtOrderOrder of Admission:
    txtCapitalCapital:
    txtDateDate Admitted:
  21. Drag a Command Button control onto the form, positioning it under the txtOrder control.
  22. In the Command Button Wizard screen, select Form Operations in the Categories list and then select Close Form in the Actions list. Click Next.
  23. In the next screen, select Text and change the text to Close. Click Next.
  24. Change the name of the control to cmdClose and click Finish.

Testing the XML Web Service

Now, open the form and test the XML Web service.

  1. Close the property sheet, if it is displayed.
  2. On the View menu, click Form View.
  3. Enter a two-digit state name in the box (for example, VA) and click Get Information.

The results of the XML Web service are displayed in the text boxes on the form (see Figure 1).

Conclusion

In this article, we demonstrated creating, deploying, and accessing an XML Web service which accepts the two-digit name of a U.S. state and returns the state's full name, its capital, the date the state was admitted to the union, and its order of admission. First, you created a virtual root on the Web server. Next, you created a simple ActiveX DLL to host our sample XML Web service. Then, you used the SOAP Toolkit 2.0 to create the WSDL and WSML files. And finally, you created an Access 2002 form as the client application and tested the XML Web service. By using the steps discussed in this article, you can create, deploy, and test your own XML Web services using Visual Basic 6.0 and Office XP.

Show:
© 2014 Microsoft