Demo link: http://code.msdn.microsoft.com/windowsazure/How-to-use-bing-search-API-4c8b287e

Aspx Code:

 <form id="form1" runat="server">
<div>
<asp:TextBox ID="tbQueryString" runat="server" Height="43px" Width="584px"></asp:TextBox>
&nbsp;<br />
<asp:Button ID="btnWebSearch" runat="server"
Text="Web Results" onclick="btnWebSearch_Click" />
&nbsp;<asp:Button ID="btnImageSearch" runat="server" Text="Image Search"
onclick="btnImageSearch_Click" />
&nbsp;<asp:Button ID="btnVideosSearch" runat="server"
Text="Videos Results" onclick="btnVideosSearch_Click" />
&nbsp;<asp:Button ID="btnNewsSearch" runat="server" Text="News Search"
onclick="btnNewsSearch_Click" />
&nbsp;<asp:Button ID="btnSpellingSuggestionSearch" runat="server" Text="Spelling Suggestion Search" onclick="btnSpellingSuggestionSearch_Click"
/>
&nbsp;<asp:Button ID="btnRelatedSearch" runat="server" Text="RelatedSearch" onclick="btnRelatedSearch_Click"
/>
&nbsp;<asp:Button ID="btnCompositeSearch" runat="server" Text="Composite Search"
Width="148px" onclick="btnCompositeSearch_Click" />
&nbsp;<br />
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
</form>

Code Behind:

using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Net;
using System.Text; namespace CSAzureMarketPlaceBingSearch
{
public partial class Default : System.Web.UI.Page
{
// Create a Bing container.
private const string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
//TODO:Change this account key to yours.
//Example:
//AgiyQkKH0B/1OTwW/zXu3hGNc2mU2OGintltk1IqajY=
private const string AccountKey = "[Account key]"; string market = "en-us";
protected void Page_Load(object sender, EventArgs e)
{ } /// <summary>
/// Search for web only.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnWebSearch_Click(object sender, EventArgs e)
{
Repeater rptResult=new Repeater(); // This is the query expression.
string query = tbQueryString.Text;
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results.
var webQuery =bingContainer.Web(query, null, null, market, null, null, null, null);
webQuery = webQuery.AddQueryOption("$top", ); // Run the query and display the results.
var webResults = webQuery.Execute();
Label lblResults = new Label();
StringBuilder searchResult = new StringBuilder(); foreach (Bing.WebResult wResult in webResults)
{
searchResult.Append(string.Format("<a href={2}>{0}</a><br /> {1}<br /> {2}<br /><br />",
wResult.Title,
wResult.Url,
wResult.Description)); }
lblResults.Text = searchResult.ToString();
Panel1.Controls.Add(lblResults); } /// <summary>
/// Search for image only.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImageSearch_Click(object sender, EventArgs e)
{
Repeater rptResult = new Repeater();
string query = tbQueryString.Text; // Create a Bing container.
string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results.
var imageQuery =
bingContainer.Image(query, null, market, null, null, null, null);
imageQuery = imageQuery.AddQueryOption("$top", ); // Run the query and display the results.
var imageResults = imageQuery.Execute();
StringBuilder searchResult = new StringBuilder();
Label lblResults = new Label(); foreach (Bing.ImageResult iResult in imageResults)
{
searchResult.Append(string.Format("Image Title: <a href={1}>{0}</a><br />Image Url: {1}<br /><br />",
iResult.Title,
iResult.MediaUrl));
}
lblResults.Text = searchResult.ToString();
Panel1.Controls.Add(lblResults);
} /// <summary>
/// Search for video only.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnVideosSearch_Click(object sender, EventArgs e)
{
Repeater rptResult = new Repeater();
string query = tbQueryString.Text; // Create a Bing container.
string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results.
var mediaQuery =
bingContainer.Video(query, null, market, null, null, null, null, null);
mediaQuery = mediaQuery.AddQueryOption("$top", ); // Run the query and display the results.
var mediaResults = mediaQuery.Execute();
Label lblResults = new Label();
StringBuilder searchResult = new StringBuilder(); foreach (Bing.VideoResult vResult in mediaResults)
{
searchResult.Append(string.Format("Video Tile: <a href={1}>{0}</a><br />Video URL: {1}<br />",
vResult.Title,
vResult.MediaUrl));
}
lblResults.Text=searchResult.ToString();
Panel1.Controls.Add(lblResults);
} /// <summary>
/// Search for news only.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewsSearch_Click(object sender, EventArgs e)
{
Repeater rptResult = new Repeater(); string query = tbQueryString.Text;
// Create a Bing container.
string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Get news for science and technology.
string newsCat = "rt_ScienceAndTechnology"; // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results.
var newsQuery =
bingContainer.News(query, null, market, null, null, null, null, newsCat, null);
newsQuery = newsQuery.AddQueryOption("$top", ); // Run the query and display the results.
var newsResults = newsQuery.Execute(); StringBuilder searchResult = new StringBuilder();
Label lblResults = new Label(); foreach (Bing.NewsResult nResult in newsResults)
{
searchResult.Append(string.Format("<a href={0}>{1}</a><br /> {2}<br /> {3}&nbsp;{4}<br /><br />",
nResult.Url,
nResult.Title,
nResult.Description,
nResult.Source,
nResult.Date));
}
lblResults.Text = searchResult.ToString(); Panel1.Controls.Add(lblResults);
} /// <summary>
/// Search with spelling suggestion.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSpellingSuggestionSearch_Click(object sender, EventArgs e)
{
string query = tbQueryString.Text; // Create a Bing container.
string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query.
var spellQuery =
bingContainer.SpellingSuggestions(query, null, market, null, null, null); // Run the query and display the results.
var spellResults = spellQuery.Execute(); List<Bing.SpellResult> spellResultList = new List<Bing.SpellResult>(); foreach (var result in spellResults)
{
spellResultList.Add(result);
} Label lblResults = new Label();
if (spellResultList.Count>)
{
lblResults.Text = string.Format(
"Spelling suggestion is <strong>{0}</strong>",
spellResultList[].Value);
}
else
{
lblResults.Text = "No spelling suggestion. Type some typo key words for suggestion for example \"xbx gamess\"";
}
Panel1.Controls.Add(lblResults); } /// <summary>
/// Related search.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnRelatedSearch_Click(object sender, EventArgs e)
{
string query = tbQueryString.Text; // Create a Bing container.
string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 10 results.
var relatedQuery =
bingContainer.RelatedSearch(query, null, market, null, null, null);
relatedQuery = relatedQuery.AddQueryOption("$top", ); // Run the query and display the results.
var relatedResults = relatedQuery.Execute(); List<Bing.RelatedSearchResult> relatedSearchResultList = new List<Bing.RelatedSearchResult>();
Label lblResults = new Label();
StringBuilder searchResults=new StringBuilder();
foreach (Bing.RelatedSearchResult rResult in relatedResults)
{
searchResults.Append(string.Format("<a href={1}>{0}</a><br /> {1}<br />",
rResult.Title,
rResult.BingUrl));
}
lblResults.Text=searchResults.ToString();
Panel1.Controls.Add(lblResults);
} /// <summary>
/// Composite search.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCompositeSearch_Click(object sender, EventArgs e)
{
string query = tbQueryString.Text;
// Create a Bing container.
string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl)); // The composite operations to use.
string operations = "web+news"; // Configure bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey); // Build the query, limiting to 5 results (per service operation).
var compositeQuery =
bingContainer.Composite(operations, query, null, null, market,
null, null, null, null, null,
null, null, null, null, null);
compositeQuery = compositeQuery.AddQueryOption("$top", ); // Run the query and display the results.
var compositeResults = compositeQuery.Execute(); StringBuilder searchResults = new StringBuilder(); foreach (var cResult in compositeResults)
{
searchResults.Append("<h3>Web Result</h3>"); // Display web results.
foreach (var result in cResult.Web)
{
searchResults.Append(string.Format("<a href={2}>{0}</a><br /> {1}<br /> {2}<br /><br />",
result.Title,result.Url,result.Description));
} searchResults.Append("<h3>News Result</h3>"); // Display news results.
foreach (var result in cResult.News)
{
searchResults.Append(string.Format("<a href={0}>{1}</a><br /> {2}<br /> {3}&nbsp;{4}<br /><br />",
result.Url, result.Title, result.Description, result.Source, result.Date));
}
} Label lblResults = new Label(); lblResults.Text = searchResults.ToString();
Panel1.Controls.Add(lblResults); } }
}

Sample-Code:Bing Search API的更多相关文章

  1. 申请Bing Search API

    地址:https://datamarket.azure.com/home 没有帐号先注册一个,然后登录. 1:在数据中订阅Bing Search API,如果找不到就使用这个地址: https://d ...

  2. 如何将经纬度利用Google Map API显示C# VS2005 Sample Code

    原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上 ...

  3. BingHack,Bing旁注API查询工具

    现在旁注查询都失效了.通过网上查询发现有人说可以通过微软的API进行旁注查询 https://datamarket.azure.com/dataset/explore/bing/search 注册登录 ...

  4. Search API 官方文档 可以用了查看自己的app

    Search API October 24, 2012 - HTTPS is now supported for Search and Lookup requests. Please update y ...

  5. 微软职位内部推荐-Sr DEV Lead, Bing Search Relevance

    微软近期Open的职位: Contact Person: Winnie Wei (wiwe@microsoft.com )Sr DEV Lead, Bing Search RelevanceLocat ...

  6. 42 Bing Search Engine Hacks

    42 Bing Search Engine Hacks November 13, 2010 By Ivan Remember Bing, the search engine Microsoft lau ...

  7. Sample Code之Web scene-slides

    这是我的第一篇随笔,在开始正文前说几句. 这个系列会记录我学习Arcgis js API 4.10的全过程,希望能对自己也对其他有需要的人有帮助.很多时候上网看一些大神的帖子会感到一头雾水,一是自己水 ...

  8. android studio2.2 的Find Sample Code点击没有反应

    1 . 出现的问题描述:           右键点击Find Sample Code后半天没有反应,然后提示 Samples are currently unavailable for :{**** ...

  9. ElasticSearch Search API 简介

    REST request URI curl 'localhost:9200/bank/_search?q=*&pretty' 1. localhost:9200/bank/_search,以 ...

随机推荐

  1. cin cout getline string

    1.C++ code, When we want to read a number whatever the type is int or double , just use cin >> ...

  2. [转]C#开发微信公众平台-就这么简单

    本文转自:http://www.it165.net/pro/html/201403/11102.html 写在前面 服务号和订阅号 URL配置 创建菜单 查询.删除菜单 接受消息 发送消息(图文.菜单 ...

  3. CSS秘密花园:多边框

    今天在查询CSS3动画相关资料时偶然发现这个,感觉有时还是挺方便的.原文链接:http://www.w3cplus.com/css3/css-secrets/multiple-borders.html ...

  4. 用Golang为Python编写模块

    Go里面需要显示的引入C模块, 让编译器支持生成动态链接库, 并且在代码中可以使用C语言的数据类型,这个至关重要. Calling Go code from Python code 摘取一个最简单例子 ...

  5. xcode恢复语法高亮

    [xcode恢复语法高亮] 非常简单,在Organizer中删除derivedData.

  6. c++之继承与派生

    再来回顾下继承派生的语法. 继承方式显示有三种(public, protected, privatez),隐式默认private.所谓继承方式,是指派生类对基类成员的访问权限控制. 派生类构造函数定义 ...

  7. AntD01 Angular2整合AntD、Angular2整合Material、利用Angular2,AntD,Material联合打造后台管理系统 ???

    待更新... 2018-5-21 13:53:52 1 环境说明 2 搭建Angular项目 详情参见 -> 点击前往 辅助技能 -> 点击前往 3 创建共享模块 ng g m share ...

  8. 自制模仿apache访问日志文件格式的php日志类

    <?php // 访问日志写入类 @author 王伟 2011.12.14class Log{        //项目跟路径    private $root_path;        //日 ...

  9. linux安全关机脚本

    linux安全关机脚本 在断电4分钟后判断关键 目的:在断电以后服务器连接UPS,UPS最多只能支持5分钟也会没电,所以在这里做个判断,如果断电4分钟后,市电还没来就关机. 以下两个设备为两个下路由器 ...

  10. jQuery--后台主机列表编辑

    先看效果: 要求: 全选,反选和取消 编辑模式下的全选,反选和取消 编辑模式下单选进入编辑状态,取消退出编辑状态 表格元素有可编辑,不可编辑,下拉选择 按住ctrl选择下拉框,下面的同列选项都随之改变 ...