MS-Access / Getting Started

Validate the Registration Using the Web Service

To validate a registration key using the service, create a new database with a standard module. Add the following VBA code to the module. We'll use the XMLHTTP object to send a GET request to the URL for the Web service.

We're using MSXML5, which is included with Office 2007.

Public Function IsValidRegistration(stRegKey As String) As Boolean
    Dim xmlhttp As Object
    Dim szUrl As String
    Dim stResponse As String
    Dim xmldom As Object

Create the XMLHTTP and DOMDocument objects as follows:

    Set xmlhttp = CreateObject("MSXML2.XMLHTTP.5.0")
    Set xmldom = CreateObject("MSXML2.DOMDocument.5.0")

Specify the URL, which includes the call to the Web service. Notice that we're performing a GET request by specifying the parameters in the URL itself.

    ' set the URL
    szUrl = "http://<ServerName>/regws/registration.asmx/IsValidPIDKey?pidKey=" &
stRegKey

Tell the XMLHTTP object to issue the GET request and send it to the server:

    ' get the XML from the web service
    xmlhttp.Open "GET", szUrl, False
    xmlhttp.send

    ' wait for a response
    While (xmlhttp.ReadyState <> 4)
	DoEvents
    Wend
    stResponse = xmlhttp.responseText

Because we are using an ASP.NET Web service, the response will come back as XML. Load this XML into a DOMDocument object using the loadXML method. We'll then parse this XML and look for the result of the IsValidPIDKey method defined in the service:

    ' parse the response
    If (Not (xmldom.loadXML(stResponse))) Then
	' could not parse - return False
	IsValidRegistration = False
    Else
	IsValidRegistration = _
	    (xmldom.documentElement.childNodes(0).nodeValue = "true")
    End If

End Function

To test the service, call the IsValidRegistration function in the Immediate window. Pass in a valid registration key twice. The function should return True the first time and False the second time when the PID table is updated.

If a Web service is not the appropriate mechanism for server validation in your architecture, there are many other methods you can use to validate a registration key. Other choices might include e-mail, telephone, key exchange using a text or XML file, or checking a file location for internal applications on a given network.

[Previous] [Contents] [Next]