Export (0) Print
Expand All

Building and Deploying Visual Basic for Applications Web Service Clients

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.
 

Harry Miller, Lori Turner and Marc La Pierre
June 2002

Applies to:
   Microsoft® Office XP
   Microsoft Visual Studio® .NET
   Microsoft Visual Studio Installer 1.0, 1.1

Summary: This article provides an overview of the Web Services References Tool 2.0 and then takes you through the process of building and deploying Visual Basic® for Applications (VBA) Web Service Clients.

Contents

Web Service References Tool 2.0
Walkthrough 1: Build a Visual Basic for Applications Web Service Client
Walkthrough 2: Call a Web Service from an Excel Worksheet Function
Walkthrough 3: Use Visual Studio .NET to Deploy a Visual Basic for Applications Web Service Client
Walkthrough 4: Use Visual Studio 6.0 Installer Version 1.x to Deploy a Visual Basic for Applications Web Service Client

Web Service References Tool 2.0

The Web Service References Tool 2.0 for Visual Basic for Applications provides an interface for discovering Web services, selecting the services you want, and creating classes that act as Web service proxies for your Visual Basic for Applications (VBA) projects. The Web Service References Tool 2.0 is available for download with the Office XP Web Services Toolkit.

Once you have installed the Office XP Web Services Toolkit, you can access the Web Service References Tool through the Visual Basic Editor in Microsoft Office applications. On the Tools menu in the Visual Basic Editor, click Web Service References to begin:

Aa140337.wsrbuildanddeploy01(en-us,office.10).gif

Figure 1: Web Service References Tool 2.0

When you add a reference to a Web service using the tool, a proxy class is added to your Visual Basic for Applications project. The proxy class is added to your project as a class module with the name of the Web service prefixed with "clsws_". This proxy class wraps calls to the Web service. You can use this proxy class to easily access the functionality that the Web service provides and incorporate that functionality into your Office solution. When you implement a Web Service in your Office solution, your Office solution is considered a Web Service client.

The proxy class uses SOAP and MSXML to interact with a Web service. Since the proxy class wraps calls to the Web Service, you do not need to write the code yourself to interact with SOAP and MSXML. However, when you decide to deploy your Office Web Service client to other computers, you must also deploy supporting files for SOAP and MSXML for your solution to work correctly on other computers that might not otherwise have these files installed.

The remainder of this article is dedicated to showing you step-by-step how you can build your own Web Service clients and deploy them. You can choose any Windows Installer-based packaging methods to deploy your Web Service client. For illustration, this article includes deployment walkthroughs using Visual Studio .NET and Visual Studio Installer 1.x.

Walkthrough 1: Build a Visual Basic for Applications Web Service Client

This walkthrough illustrates how you can add a Web service to a Visual Basic for Applications project and call a method in that service. The sample Web service you will reference is the EightBall Web service. You will write code that calls the Ask method in the EightBall Web Service; this method accepts a question as a parameter and returns a random answer.

Note:   For details on the EightBall Web service, visit http://www.gotdotnet.com/playground/services/EightBall.aspx.

While this walkthrough shows how you can use a Web service in Microsoft Word, it does not incorporate any functionality that is specific to Word. Therefore, you can use these same steps in other Office applications – Microsoft Excel, Microsoft PowerPoint® or Microsoft Access – to reference and call a Web service.

  1. Start a new document in Microsoft Word.
  2. On the Tools menu, click Macro, and then click Visual Basic Editor.
  3. On the Tools menu in the Visual Basic Editor, click Web Service References. The Web Service References Tool 2.0 dialog box appears.
  4. Add a reference to the EightBall Web Service:
    1. Type "GotDotNet" for the Business Name and click Search. Your search criteria is submitted to the UDDI server; the results are shown in the Search Results window as a list of Web services and methods.
    2. Select EightBallWS in the Search Results list and click Add. The proxy class for the Web Service is added to the project and named "clsws_EightBallWS".
  5. On the Insert menu in the Visual Basic Editor, click Module to add a code module to your project. The code module is named "Module1" by default.
  6. In Module1, type the following code:
    Public Function AskEightBall(sQuestion as String) as String
       Dim wAnswer As New clsws_EightBallWS
       AskEightBall = wAnswer.wsm_Ask(sQuestion)
    End Function
    
    Public Sub TestEightBall()
       Dim sQuestion As String
       sQuestion = InputBox("What is your question for EightBall?")
       MsgBox AskEightBall(sQuestion)
    End Sub
    
  7. Place your cursor anywhere inside the TestEightBall procedure and press F5 to run it.
  8. When prompted for a question, type "Does this sample work?" and click OK.
    The procedure creates a new instance of the Web service proxy class (clsws_EightBallWS) and calls the Ask method with your question as a string parameter. The Web service returns a random string as your answer.

Walkthrough 2: Call a Web Service from an Excel Worksheet Function

This walkthrough demonstrates how you can build upon the previous example by integrating a Web service with Office functionality. You will use an Excel worksheet function to send a question to the EightBall Web Service and have the results returned to a cell.

  1. Start a new workbook in Microsoft Excel.
  2. Perform steps 2 through 6 in Walkthrough 1.
  3. Close the Visual Basic Editor to return to your Excel workbook.
  4. Type any question in cell A1.
  5. Select cell A2.
  6. Enter a worksheet function to call the EightBall Web Service:
    1. On the Insert menu, click Function. The Function Wizard appears.
    2. In the Or select a category list dropdown, click User Defined.
    3. In the Select a function list, click AskEightBall and then click OK. The Function Arguments dialog box appears.
    4. Type "A1" for the sQuestion parameter in the Function Arguments dialog box and click OK. The answer to your question appears in cell A2.
    5. Change your question in cell A1 to see cell A2 recalculate, or display a new answer.
  7. Save the workbook as MagicEightBall.xls.

Walkthrough 3: Use Visual Studio .NET to Deploy a Visual Basic for Applications Web Service Client

Create and Build a Setup Project

  1. Start Visual Studio .NET.
  2. Create a new setup project:
    1. On the File menu, click New and then click Project. The New Project dialog box appears.
    2. In the New Project dialog box, select Setup and Deployment Projects for the project type and choose Setup Project for the template.
    3. Type "Magic Eight Ball" for the project name and "C:\" for the project location.
    4. Click OK.
  3. Click the Magic Eight Ball project in Solution Explorer and examine the ProductName property. The ProductName property determines the name that will be used for the application in folder names and in the Add/Remove Programs dialog box.
  4. Add MagicEightBall.xls to your Setup project:
    1. On the Project menu, click Add and then click File. The Add File dialog box appears.
    2. Browse to locate MagicEightBall.xls and click Open.
  5. Add the Microsoft SOAP 3.0 MSM file to your Setup project:
    1. On the Project menu, click Add and then click Merge Module. The Add Modules dialog box appears.
    2. Browse to locate soap_core.msm and click Open.
      Note:   The default path for soap_core.msm is C:\Program Files\Common Files\Microsoft Shared\Web Service Reference\Redist\soap_core.msm.
  6. Add the Microsoft XML 4.0 MSM File to your Setup project:
    1. On the Project menu, click Add and then click Merge Module. The Add Modules dialog box appears.
    2. Browse to locate MSXML4.MSM and click Open.
      Note: The default path for MSXML4.MSM is C:\Program Files\Common Files\Microsoft Shared\Web Service Reference\Redist\1033\MSXML4.MSM.
  7. Add instructions for the installer to create a desktop shortcut for the Magic Eight Ball solution:
    1. Double click the MagicEightBall.xls file in Solution Explorer to display the File System Editor.
    2. In the File System Editor, select MagicEightBall.xls under the Application Folder node.
    3. On the Action menu, click Create Shortcut to MagicEightBall.xls.
    4. Change the name of the shortcut to "Magic Eight Ball".
    5. Drag the "Magic Eight Ball" shortcut to the User's Desktop node in the File System Editor.
  8. On the Build menu, click Build Magic Eight Ball to build the application.
  9. On the Project menu, click Install to test the installation.
  10. On the Project menu, click Uninstall to remove the application.

Deploy Your Solution to Another Computer

  1. In Windows Explorer, browse to the "C:\Magic Eight Ball\Debug" folder.
    Note: The default project configuration in Visual Studio .NET is Debug; if you used a Release configuration, you should instead browse to the "C:\Magic Eight Ball\Release" folder.
  2. Copy all files in the Debug folder to the target computer. Alternatively, you may copy them to a network share.
    Note: To install on a computer that is not on a network, copy the files to traditional media such as CD-ROM.
  3. On the target computer, run Setup.exe.
  4. Test the installation:
    1. Double-click the "Magic Eight Ball" shortcut on the desktop. MagicEightBall.xls is opened in Microsoft Excel.
    2. Type a question in cell A1. Your answer appears in cell A2.
    3. Use the Add/Remove Programs tool in the Windows Control Panel to uninstall "Magic Eight Ball".

For more information about using Visual Studio .NET to deploy applications, see:

Walkthrough 4: Use Visual Studio 6.0 Installer Version 1.x to Deploy a Visual Basic for Applications Web Service Client

Create and Build a Setup Project

  1. Start Visual Studio Installer. The New Project dialog box appears.
  2. Select Visual Studio Installer Projects under the Visual Studio node.
  3. Choose Empty Installer for the project type.
  4. Type "Magic Eight Ball" for the project name and click Open to create the new project.
  5. On the Project menu, click File System.
  6. Add MagicEightBall.xls to your Setup project:
    1. On the Project menu, click Add File(s). The Browse for Files dialog box appears.
    2. Browse to locate MagicEightBall.xls and click Open.
  7. Add the Microsoft SOAP 3.0 MSM file to your Setup project:
    1. On the Project menu, click Add Merge Module(s). The Browse for Merge Module dialog box appears.
    2. Browse to locate soap_core.msm and click Open.
      Note:   The default path for soap_core.msm is C:\Program Files\Common Files\Microsoft Shared\Web Service Reference\Redist\soap_core.msm.
  8. Add the Microsoft XML 4.0 MSM File to your Setup project:
    1. On the Project menu, click Add Merge Module(s). The Browse for Merge Modules dialog box appears.
    2. Browse to locate MSXML4.MSM and click Open.
      Note: The default path for MSXML4.MSM is C:\Program Files\Common Files\Microsoft Shared\Web Service Reference\Redist\1033\MSXML4.MSM.
  9. Add instructions for the installer to create a desktop shortcut for the Magic Eight Ball solution:
    1. Double click the MagicEightBall.xls file in Solution Explorer to display the File System Editor.
    2. In the File System Editor, select MagicEightBall.xls under the Application Folder node.
    3. On the Actions menu, click Create Shortcut.
    4. Change the name of the shortcut to "Magic Eight Ball".
    5. Drag the "Magic Eight Ball" shortcut to the User's Desktop node in the File System Editor.
  10. On the Build menu, click Build.
  11. On the Project menu, click Magic Eight Ball Properties. Select Installer With Windows Installer Loader for the Build Type and click OK.
  12. On the Project menu, click Launch Installer to test the installation.

Deploy Your Solution to Another Computer

  1. In Windows Explorer, browse to the folder for the Magic Eight Ball project. Copy all the files in ..\Magic Eight Ball\Output\DISK_1 to the target computer or to a network share. By default, Visual Studio Installer projects are saved to your My Documents folder.
    Note:   To install on a computer that is not on a network, copy the file to traditional media such as CD-ROM.
  2. On the target computer, run Setup.exe.
  3. Test the installation:
    1. Double-click the "Magic Eight Ball" shortcut on the desktop. MagicEightBall.xls is opened in Microsoft Excel.
    2. Type a question in cell A1. Your answer appears in cell A2.
    3. Use the Add/Remove Programs tool in the Windows Control Panel to uninstall "Magic Eight Ball".
Note:   Visual Studio Installer 1.0 and 1.1 are available for download. For download information, please visit Installer 1.1.

For more information about using Visual Studio Installer to deploy applications, see:

Note:   The SOAP client and XML require that you use Window Installer Version 2.0. For more details, see the following article:
Show:
© 2014 Microsoft