People Search web service VB.NET example

The following VB.NET code example enables you to easily get up and running with the People Search web service. Simply use the authentication credentials supplied to you on sign up which we have made available to you in the My Account section.

You will likely prefer to use one of of the available OAuth libraries to handle client authentication. The OAuth library used in the following example is listed separately.

Whilst our code examples demonstrate the breadth of our capabilities, all of our examples are created using demo data and do not contain real or live personal data relating to data subjects.

Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.IO
Imports System.Net
Imports System.Web.Script.Serialization
 
' note that my project name was called Peoplesearch_VB
Imports Peoplesearch_VB.OAuth
 
 
Namespace Tracesmart.VBNet.Api
    Public Class PeoplesearchService
 
        ' Your consumer key and secret as supplied by Tracesmart
        Private Const ConsumerKey As String = "b8e601941ad09b9478ac76c25b3bb46e10b8bdad"
        Private Const ConsumerSecret As String = "3065d6fa76t2da717bc5765388a8795a45245583"
 
        Public Sub MakeTestRequest()
            Dim parameters As IDictionary(Of String, String) = New Dictionary(Of String, String)() From { _
             {"name1", "Heather Russell"}, _
             {"dob1", ""}, _
             {"name2", ""}, _
             {"location", "BS7"}, _
             {"alias", ""}, _
             {"strictMiddle", "1"}, _
             {"withoutDOB", "1"}, _
             {"withInitial", "1"}, _
             {"requestReference", "My Unique Reference"} _
            }
            Dim response = New PeoplesearchService().MakeRequest(parameters)
            Dim matches = TryCast(response("matches"), Object())
 
            Debug.WriteLine("Found " & matches.Length & " possible matches")
            For Each match As IDictionary(Of String, Object) In matches
                Debug.WriteLine(match("name"))
            Next
        End Sub
 
        Public Function MakeRequest(parameters As IDictionary(Of String, String)) As IDictionary(Of String, Object)
            Dim httpWebRequest = BuildRequest(parameters)
            Try
                Using httpWebResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
                    Dim jsonResponse = ReadResponseToText(httpWebResponse)
                    Debug.WriteLine("Received json from the server:")
                    Debug.WriteLine(jsonResponse)
                    Return New JavaScriptSerializer().Deserialize(Of IDictionary(Of String, Object))(jsonResponse)
                End Using
            Catch ex As WebException
                Throw New PeoplesearchServiceException(If(ReadResponseToText(ex.Response), ex.Message), ex)
            End Try
        End Function
 
        Private Function ReadResponseToText(response As WebResponse) As String
            If response Is Nothing Then
                Return Nothing
            End If
            Using responseStream = New StreamReader(response.GetResponseStream())
                Return responseStream.ReadToEnd()
            End Using
        End Function
 
        Private Function BuildRequest(parameters As IDictionary(Of String, String)) As HttpWebRequest
            ' This is a live API, please contact us if you need to perform load, volume or security testing
            Dim rawRequestUrl = New Uri("https://api.tracesmart.co.uk/peoplesearch/v1/match" & ToQueryString(parameters))
            Dim normalizedUrl As String
            Dim requestParameters As String
            Dim oAuth = New OAuthBase()
            Dim signature = oAuth.GenerateSignature(rawRequestUrl, ConsumerKey, ConsumerSecret, Nothing, Nothing, "POST", _
             oAuth.GenerateTimeStamp(), oAuth.GenerateNonce(), OAuthBase.SignatureTypes.HMACSHA1, normalizedUrl, requestParameters)
            Dim requestUrl = New Uri(normalizedUrl)
            Dim httpRequest = DirectCast(System.Net.WebRequest.Create(requestUrl), HttpWebRequest)
            httpRequest.Method = "POST"
            httpRequest.ContentType = "application/x-www-form-urlencoded"
            Using requestStream = New StreamWriter(httpRequest.GetRequestStream())
                requestStream.Write(requestParameters & "&oauth_signature=" & OAuthBase.UrlEncode(signature))
            End Using
 
            Return httpRequest
        End Function
 
        Private Function ToQueryString(parameters As IDictionary(Of String, String)) As String
            Return "?" & String.Join(
                "&", New List(Of String)(parameters.Keys).ConvertAll(
                    Function(key) String.Format(
                        "{0}={1}", OAuthBase.UrlEncode(key), OAuthBase.UrlEncode(parameters(key))
                    )
                ).ToArray()
            )
        End Function
    End Class
 
    Public Class PeoplesearchServiceException
        Inherits Exception
        Public Sub New(message As String, innerException As Exception)
            MyBase.New(message, innerException)
        End Sub
    End Class
End Namespace
 

An example of code that might make use of the previous class is listed below:

Public Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim peoplesearch = New Tracesmart.VBNet.Api.PeoplesearchService()
        peoplesearch.MakeTestRequest()
    End Sub
 
End Class

From this juncture you should refer to the higher level documentation which explains how to send a request.