In this article, i will examined how to integrate Microsoft Bing Search engine on your site. First, you would have to get APPID from Microsoft site. Here is a link.
In next step, in your project add the following web reference.
http://api.search.live.net/search.wsdl?AppID=YourAppId
Here is code snippets to make a call in c#.
1: LiveSearchService service = new LiveSearchService();
2: SearchRequest request = new SearchRequest();
3:
4: request.AppId = "YOUR APPID";
5: request.Query = Keyword.Text;
6:
7: request.Sources = new SourceType[] { SourceType.Web };
8:
9: SearchResponse response = service.Search(request);
10:
11: StringBuilder sb = new StringBuilder();
12:
13: foreach (WebResult result in response.Web.Results)
14: {
15: sb.AppendFormat("<a href=\"{0}\">{1}</a>", result.Url, result.Title);
16: sb.AppendFormat("<br />{0}<br />", result.Description);
17: }
18:
19: Result.Controls.Add(new LiteralControl(sb.ToString()));
Here is our ASPX Code.
1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3: <html xmlns="http://www.w3.org/1999/xhtml">
4: <head runat="server">
5: <title>Untitled Page</title>
6: </head>
7: <body>
8: <form id="form1" runat="server">
9: <div>
10: <asp:TextBox ID="Keyword" runat="server"></asp:TextBox>
11: <asp:Button ID="btnSearch" runat="server"
12: Text="Search" onclick="btnSearch_Click" />
13: <br />
14: <asp:Label ID="Result" runat="server"></asp:Label>
15: </div>
16: </form>
17: </body>
18: </html>
Here is our demo page.
For more information, please visit to Microsoft site.
Summary
In this article, we examined how to integrate Microsoft Bing Search engine on your site.