Friday, 13 July 2012

Using Bing Search API in Azure

You may have received the following e-mail from Microsoft with "This is a reminder that the Bing Search API 2.0 will continue to be available until August 1, 2012." as the opening line



Here's how to move to the new API on Azure

Register and Create a new Key at https://datamarket.azure.com/account/keys

Register for Bing Search (web only) https://datamarket.azure.com/dataset/8818f55e-2fe5-4ce3-a617-0b8ba8419f65

Download .NET C# Class Library from https://datamarket.azure.com/dataset/explore/getproxy/8818f55e-2fe5-4ce3-a617-0b8ba8419f65

Add the BingSearchContainer.cs to your project


Create a repeater on your page

<asp:Repeater ID="RepeaterBingResults" runat="server">
<ItemTemplate>
<a href="<%# DataBinder.Eval(Container.DataItem, "Url") %>" target="_blank">

<%# DataBinder.Eval(Container.DataItem, "Title") %></a>
<div style="font-size:x-small"><%# DataBinder.Eval(Container.DataItem, "Description")%></div>
</ItemTemplate>
</asp:Repeater>


 In Your search button Click Event add in the following code
BingSearchContainer bing = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/SearchWeb/"));
bing.Credentials = new NetworkCredential("YourAccountKey", "YourAccountKey");
DataServiceQuery<WebResult> results = bing.Web(RadTextBoxSearchText.Text, "en-gb", "strict", null, null, null, null, null);

Then bind your repeater
RepeaterBingResults.DataSource = results.Execute().ToList();
RepeaterBingResults.DataBind();