Checking Book Prices over the Web Using the Web Service References Tool and Microsoft Outlook

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.

 

Paul Cornell
Microsoft Corporation

January 2002

Applies to:
     Microsoft® Outlook 2002

Summary: A sample solution that checks book prices over the Internet using the Web Service References Tool and Microsoft Outlook. (4 printed pages)

Contents

Introduction
Running the Solution
Examining the Code
Conclusion

Introduction

The solution described in this article uses the SalesRankNPrice Web service (http://www.perfectxml.net/WebServices/SalesRankNPrice/BookService.asmx?WSDL), provided by PerfectXML (http://www.perfectxml.com), along with the Web Service References Tool, to check book prices over the Internet using Microsoft Outlook.

This solution assumes that you already have the Web Service References Tool installed on your development computer, and that end users' computers have the following software installed:

  1. The Microsoft Soap Type Library (mssoap1.dll), available with one of the following software components:
  2. The Microsoft XML (MSXML) Parser. For information about which Microsoft products ship the MSXML Parser, see the Microsoft Knowledge Base article Q269238, INFO: Version List of the Microsoft XML Parser. Alternatively, you can download the MSXML Parser from the MSDN Online XML Developer Center.

Running the Solution

To run this solution:

  1. Add the clsws_SalesRankNPrice.cls file and mod_SalesRankAndPrice.bas files (located in the \samples\PriceCheck folder of the Office XP Web Services Toolkit) to an Outlook VBA project.
  2. Open your Inbox in Outlook.
  3. On the File menu, point to New, and click Post in This Folder.
  4. In the Subject box, type ISBN: followed by an International Standard Book Number (ISBN). ISBNs can be found on the back covers of most books. Do not use hyphens, spaces, or other punctuation in typing the ISBN.
  5. Run the GetSalesPrices subroutine in the mod_SalesRankAndPrice code module. Notice the book prices are now visible in the bodies of the corresponding post items.

Examining the Code

Let's examine the code behind this solution.

As usual with Outlook applications, objects of type Application, NameSpace, and MAPIFolder are declared, along with a generic object to iterate through Inbox post items.

    Dim olApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objFldr As Outlook.MAPIFolder
    Dim objItem As Object

An object of type clsws_SalesRankNPrice is declared to reference the Web service.

    Dim objSales As clsws_SalesRankNPrice

An object of type IXMLDOMNodeList is declared to parse the Web service's returned data.

    Dim objResults As MSXML2.IXMLDOMNodeList

Finally, an array of strings is declared to hold the parsed ISBN.

    Dim strISBN() As String

Three constants are declared, representing various ordinal numbers, for readability.

    Const ISBN_ARRAY_ELEMENT As Integer = 1
    Const AMAZON_NODE As Integer = 1
    Const BN_NODE As Integer = 3

The Application, NameSpace, and MAPIFolder objects are initialized to reference the Inbox.

    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace(Type:="MAPI")
    Set objFldr = objNS.GetDefaultFolder(FolderType:=olFolderInbox)

The clsws_SalesRankNPrice object is initialized.

    Set objSales = New clsws_SalesRankNPrice

Each item in the Inbox is examined. If the item is a post item and starts with the string ISBN:, the program continues.

    For Each objItem In objFldr.Items
        If objItem.Class = olPost And _
                InStr(1, objItem.SUBJECT, "ISBN:") = 1 Then

The ISBN number is parsed.

            strISBN = Split(objItem.SUBJECT, ":")

Information about the ISBN is returned from the Web service as an IXMLDOMNodeList object.

            Set objResults = objSales.wsm_GetAmazonAndBNPrice _
                (strISBN(ISBN_ARRAY_ELEMENT))

The Web service method wsm_GetAmazonAndBNPrice corresponds to the following code in the clsws_SalesRankNPrice.cls file:

...
Private sc_SalesRankNPrice As SoapClient
Private Const c_WSDL_URL As String = _
    "http://www.perfectxml.net/WebServices/SalesRankNPrice/
      BookService.asmx?WSDL"

Set sc_SalesRankNPrice = New SoapClient
sc_SalesRankNPrice.mssoapinit c_WSDL_URL

Public Function wsm_GetAmazonAndBNPrice(ByVal str_ISBN As String)
  As Object

    Set wsm_GetAmazonAndBNPrice = _
        sc_SalesRankNPrice.GetAmazonAndBNPrice(str_ISBN)

The information is parsed and written to the body of the post item.

            objItem.Body = "Amazon price: " & _
                objResults.Item(AMAZON_NODE).nodeTypedValue & _
                vbCrLf & "Barnes & Noble price: " & _
                objResults.Item(BN_NODE).nodeTypedValue
            objItem.Save
        End If
        
    Next objItem

Conclusion

In this article, you saw how to create a solution that uses the Web Service References Tool and Outlook to check book prices over the Internet.