How To: Live Search 101

I have recently started playing with some of the Live Services available at https://dev.live.com. There are some pretty interesting Web Services they have been putting together. I started playing with the Live Search Service you can find at https://search.dev.com. The following is a simple example to show how to use this service with VB.

Note:

Before using this you will need to get a developer token at https://search.live.com/developer.

This is required for the example.

 

In this example we will create a very simple Windows form application that uses the Live Search Service.

1.       Create a new Windows form application that contains the following controls named as shown

 

2.       In the code behind BTNSearch enter the following code

Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click

        If TxtSearch.Text = "" Then

            MsgBox("Please Enter a search string")

        Else

            Dim searchRequest As New com.msn.search.soap.SearchRequest

 

            Dim NewRequest(0) As com.msn.search.soap.SourceRequest

            NewRequest(0) = New com.msn.search.soap.SourceRequest

            NewRequest(0).Source = com.msn.search.soap.SourceType.Web

            NewRequest(0).ResultFields = com.msn.search.soap.ResultFieldMask.All

 

            searchRequest.Query = TxtSearch.Text

            searchRequest.Requests = NewRequest

 

            ' Replace with your own developer ID from https://search.live.com/developer

            searchRequest.AppID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

            searchRequest.CultureInfo = "en-US"

 

            Dim SearchService As New com.msn.search.soap.MSNSearchService

            Dim SearchResponse As New com.msn.search.soap.SearchResponse

            SearchResponse = SearchService.Search(searchRequest)

 

            With DataGridView1

                .AutoGenerateColumns = True

                .DataSource = SearchResponse.Responses(0).Results

                .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders

 

                ' Set the DataGridView control's border.

                .BorderStyle = BorderStyle.Fixed3D

                .Refresh()

            End With

        End If

    End Sub

 

When the application is run it looks like the following

The Live Search guys have done a great job in providing an interactive SDK that you can find at https://dev.live.com/livesearch/sdk/ . This SDK provides some pretty cool examples and additional information around using these API’s.

Comments

  • Anonymous
    August 30, 2007
    Have you tried doing this in Visual Studio 2008? I don't get offered the MSNSearchService class. If I go back to 2005, then I get it fine... (admittedly this is when doing it in C#) SL

  • Anonymous
    August 30, 2007
    No I haven't tried it yet in VS 2008 yet. Are you using the latest beta? Will need to give it a try myself to see