Search API in VB.net Using the SOAP API of LiveSearch
This was going to be a TUT on using google API search (Soap API) , but the Tut has changed for good reasons, they have discontinued the Google Search API and replaced it with the Search Ajax API (which isn't suitable for us at this time)
Instead this will be a TUT on using Microsoft© Bing SOAP API to add a Search Engine feature to your VB.net application.
1st you will need a AppID you can get that by going to
Code:
http://www.bing.com/developer
if it doesn't show the * = B I N G
Once you get your APPID you need the LiveSearch API, and you are going to need your APPID to get this
Open up VB.Net and in your solutions explorer , right click your project name and click add service reference.
In the addressbar add the following address
Code:
http://api.search.live.net/search.wsdl?AppID=YOUR_APPID
Replace Your_APPID with your actual AppId, You should now see a reference to liveSearch API
On the bottom change the name of the service to something practical , something like "LiveS"
Click Ok, and View your code, adding the reference is not enough, now we need to Import and Declare.
In the Namespace (Upper most part of the code page)
Code:
Imports appname.lsearch
We will also need to use StreamReader , to use this we need to also
Code:
Imports System.Text
Note: Appname = Your application name, so if your app was called Search, it would be search.Lsearch Add a TextBox and Button to your form and a webbrowser to display results
Note: Using a Webbrowser is easiest for this tut, yes you can display results in Listviews etc, but then would need to generate more code for links etc...
Code:
'Button Click Event
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim client As New LiveSearchPortTypeClient()
Dim request As New SearchRequest()
Request.AppId = **************** ' * = Your AppID
request.Sources = New SourceType() {SourceType.Web}
request.Query = TextBox1.Text
Dim response As SearchResponse = client.Search(request)
DisplayResults(response.Web.Results)
End Sub
'Displays Results in the webbrowser
Private Sub DisplayResults(ByVal results As WebResult())
Dim sb As New StringBuilder()
results.ToList().ForEach(Function(x) sb.Append (GetFormattedResult(x)))
WebBrowser1.DocumentText = sb.ToString()
End Sub
Private Function GetFormattedResult(ByVal result As WebResult) As String
Dim formattedResult As String = (("<a href=" & result.Url & ">") + result.Title & "</a><br/>") + result.Description & "<br/><br/>"
Return formattedResult
End Function
I gave the code as a method for C&P, I didn't add images but only because I don't have PShop on this laptop, and I'm doing this side by side with work I wasn't leaving this laptop
HAVE FUN!!!!!!! This is number two of my now 10 tut requests

, glad to be done with it