Contact ePostcode.com on +44 (0)845 094 2633  
  
Classic ASP

Getting Started with ASP and VBScript

Using the Microsoft MSXML Component to call the ePostcode Web Service

You will need to download and install the MSXML 4.0 SP2 from Microsoft Downloads.

Please Note: We have recently updated the web service and added new functionality for Geographic Data and 'Nearest To' Data as well as a major upgrade to our Address and Postcode Lookup functions. Because of this some of our downloads are currently unavailable. We are endeavouring to get these published as soon as possible. Meanwhile if you require any assistance with integration please give us a call.

Download
MSXML 4.0 SP2 download
ePostcodeASP.zip Classic ASP download.

Classic ASP download. This is a download of some simple Classic ASP pages that can be incorporated in to your site. (Beginner/Intermediate developer)


This example uses the SearchPremise_ByAddress and GetPremiseAddress methods of the ePostcode web service:

http://ws.epostcode.com/uk/postcodeservices.asmx

The following code snippets detail how to retrieve a list of Addresses by searching on Postcode and retrieving the Full Postal Address for the selected Address.

Step 1

The first thing to do is to set up the Initial Search Postcode page. In the download this page is called ePostcodeASP1.asp. This is a simple page consisting of 3 Input boxes and a Submit button. The html for this page is shown below:

<html>
 <body>
 <form method="post" action="ePostcodeASP2.asp">
     <table ID="Table1">
          <tr>
              <td>Enter ePostcode Account Name</td>
              <td><input type="text" name="AccountName" ID="Text1"></td>
          </tr>
          <tr>
              <td>Enter ePostcode GUID</td>
              <td><input type="text" name="LicenceID" ID="Text2"></td>
          </tr>
          <tr>
              <td>Enter Postcode</td>
              <td><input type="text" name="Postcode" ID="Text3"></td>
          </tr>
     </table>
     <BR>
     <input type="submit" value="Get Address List">
 </form>
 </body>
</html>

The post Action of this page is "ePostcodeASP2.asp" and when the "Get Address List" button is pressed the ePostcodeASP2.asp page is loaded.

Step 2

The next thing to do is to set up the page that returns the list of addresses. In the download this page is called ePostcodeASP2.asp. This page consists of server-side VBScript code that does the hard work of calling the web service and populating an Array containing the ListAddress and the AbsRecNum of the returned Addresses.

This data is then populated into a listbox when the html is rendered.

The vbscript for this page is shown below:

<%
Dim xmlhttp,Fields,URL,objReturn, s
Dim arrList()
   
URL = "http://ws.epostcode.com/uk/postcodeservices.asmx?op=SearchPremise_ByPostcode"
Fields = "sPostcode=" & Request.Form("Postcode") & _
        "&AccountName=" & Request("AccountName") & _
        "&LicenceID=" & Request("LicenceID") & _
  "&MachineID="
   
Set xmlhttp = CreateObject("MSXML2.xmlhttp")
xmlhttp.Open "POST", URL, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.Send Fields
   
Set objReturn = CreateObject("MSXML2.DOMDocument")
objReturn.LoadXml xmlhttp.responseText
   
If objReturn.hasChildNodes Then
 Dim i,sAbsRecNum ,sListAddress,objReturn2
 Dim iNumAddresses
 
 
 
  Set objReturn2 = CreateObject("MSXML2.DOMDocument") 
  iNumAddresses = objReturn.getElementsByTagName("ListAddressPremise").Length
       
        If iNumAddresses > 0 Then
            ReDim arrList(iNumAddresses,1)
        End If         
       
  For i = 0 To objReturn.getElementsByTagName("ListAddressPremise").Length - 1
            objReturn2.loadXML objReturn.getElementsByTagName("ListAddressPremise").Item(i).XML
            If objReturn2.hasChildNodes Then
               sAbsRecNum = objReturn2.getElementsByTagName("Unique_Delivery_Point").Item(0).Text
               sListAddress = objReturn2.getElementsByTagName("List_Address").Item(0).Text
               arrList(i,0)=sAbsRecNum
               arrList(i,1)=sListAddress
    
   End If
  Next
End if

The Addresses are populated into a Listbox from the array as shown below in the html.

<html>
 <body>
  <form method="post" action="ePostcodeASP3.asp" ID="Form1">
   Select Address From List
   <INPUT id="Hidden1" type="hidden" name="AccountName" value="<% = Request("AccountName") %>">
   <INPUT id="Hidden2" type="hidden"  name="LicenceID" value="<% = Request("LicenceID") %>">
   <BR>
   <BR>
   <select name="ListAddress" size="20" ID="Select1">
   <%For i = 0 To UBound(arrList) - 1%>
    <option value="<% = arrList(i,0) %>">
     <% = arrList(i,1) %>
    </option>
   <%Next%>
   </select>
   <BR>
   <BR>
   <input type="submit" name="btnSubmit" value="Get Address">
  </form>
 </body>
</html>

The post Action of this page is "ePostcodeASP3.asp" and when the "Select Address" button is pressed the ePostcodeASP3.asp page is loaded.

Step 3

The next thing to do is to set up the page that returns the selected address. In the download this page is called ePostcodeASP3.asp. This page consists of server-side VBScript code that returns the selected address from the AbsRecNum of the selected address obtained from the selected Item in the Listbox on ePostcodeASP2 page.

This data is then populated when the html is rendered.

The vbscript for this page is shown below:

<%
 Dim xmlhttp
    Dim Fields
    Dim URL
    Dim objReturn
   
    URL = "http://ws.epostcode.com/uk/postcodeservices.asmx?op=GetPremiseAddress"
    Fields = "sUniqueDeliveryPointID=" & Request("ListAddress") & _
        "&AccountName=" & Request("AccountName") & "&LicenceID=" & Request("LicenceID") & "&MachineID="
   
    Set xmlhttp = CreateObject("MSXML2.xmlhttp")
    xmlhttp.Open "POST", URL, False
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.Send Fields
   
    Set objReturn = CreateObject("MSXML2.DOMDocument")
    objReturn.loadXML xmlhttp.responseText
   
    If objReturn.hasChildNodes Then
  'continue
    Else
  Response.Write "Error"
  Response.End
    End If
%>

The Address is populated as shown below in the html.

<html>
 <body>
  <table>
   <%If Request.Form("btnSubmit")="Get Address" then%>
    <%If objReturn.getElementsByTagName("Return_Code").Item(0).Text = "1" then%>
     <tr>
      <td>Organisation Department</td>
      <td><% = objReturn.getElementsByTagName("Organisation_Department").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Organisation</td>
      <td><% = objReturn.getElementsByTagName("Organisation").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Sub Building Name</td>
      <td><% = objReturn.getElementsByTagName("Sub_Building_Name").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Building</td>
      <td><% = objReturn.getElementsByTagName("Building_Name").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Number</td>
      <td><% = objReturn.getElementsByTagName("Number").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Dependent Street</td>
      <td><% = objReturn.getElementsByTagName("Dependent_Street").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Street</td>
      <td><% = objReturn.getElementsByTagName("Street").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Double Dependent Locality</td>
      <td><% = objReturn.getElementsByTagName("Double_Dependent_Locality").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Dependent Locality</td>
      <td><% = objReturn.getElementsByTagName("Dependent_Locality").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Post Town</td>
      <td><% = objReturn.getElementsByTagName("Post_Town").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Country</td>
      <td><% = objReturn.getElementsByTagName("Country").Item(0).Text %></td>
     </tr>
     <tr>
      <td>Postcode</td>
      <td><% = objReturn.getElementsByTagName("Postcode").Item(0).Text %></td>
     </tr>
    <%Else%>
     <tr>
      <td>Error Message</td>
      <td><% = objReturn.getElementsByTagName("Return_Code").Item(0).Text %></td>
     </tr>
    <%End If%>
   <%End If%>
  </table>  
 </body>
</html>

If you have not already signed-up for an account click here Sign-Up Now.
You will receive your Access Codes by email and you will receive 50 free credits.

When you have your Access Codes ready you will be able to use them in the above example. You can then incorporate the code into your own ASP pages.

The other methods of the ePostcode Web Service can be used in a similar way.

For a full technical description of the ePostcode web service and the 3 methods click on the following link Web Service Described
If you have any questions feel free to contact us at the following link Contact Us.