VB.NET Store Locator Software Sample Code

 

This is a simple VB.NET sample, showing how to call the search api.

JSON deserialization is done with Json.NET.

Example: 
Imports System.Net
Imports System.IO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
 
Module Module1
 
    Sub Main()
        Dim url As String
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
 
        Try
 
            url = "http://ws.bullseyelocations.com/RestSearch.svc/DoSearch2" _
                + "?ClientId=999&ApiKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" _
                + "&CountryId=1&PostalCode=08873&Radius=10" _
                + "&StartIndex=0&PageSize=25"
 
            request = DirectCast(WebRequest.Create(url), HttpWebRequest)
            response = DirectCast(request.GetResponse(), HttpWebResponse)
            reader = New StreamReader(response.GetResponseStream())
 
            Dim rawresp As String
            rawresp = reader.ReadToEnd()
            Console.WriteLine(rawresp)
 
            ' use LINQ via JSON.NET:
            Console.WriteLine(vbLf & "Extracting location names via JSON:")
 
            Dim jResults As JObject = JObject.Parse(rawresp)
 
            Dim jq = From row In jResults("ResultList").Children()
                     Order By row("Name")
                     Select row("Name")
 
            For Each rowName In jq
                Console.WriteLine(rowName)
            Next
 
        Finally
            If Not response Is Nothing Then response.Close()
        End Try
 
        Console.WriteLine("Press any key...")
        Console.ReadKey()
    End Sub
 
End Module