所谓Bing API,就是微软的搜索服务所公开的一套API,其目的就是让任何应用程序可以调用Bing的服务实现自定义的搜索体验。

基本的三个步骤:

申请一个App Id

http://cn.bing.com/developers/createapp.aspx

下载SDK

http://www.microsoft.com/downloads/details.aspx?FamilyId=0F513086-078B-47A8-A889-842DC93A69AB&displaylang=en

如何编程访问bing的搜索服务

http://msdn.microsoft.com/en-us/library/dd251049.aspx

我做的一个例子:

我们可以采用SOAP的方式,即调用Web Service的方式,首先按照下面这样的方式添加引用

Using SOAP (Bing, Version 2)

The Bing SOAP interface is most efficiently accessed by referencing the Web Service Description Language (WSDL) document from a Microsoft Visual Studio project. The WSDL defines the ports and messages that comprise the Bing API SOAP web service.

To add a Web reference in Microsoft Visual Studio

<?XML:NAMESPACE PREFIX = [default] http://ddue.schemas.microsoft.com/authoring/2003/5 NS = "http://ddue.schemas.microsoft.com/authoring/2003/5" />

  1. From Solution Explorer in an existing or newly created project, right-click References and, from the pop-up menu, select Add Service Reference.
    If you are using Microsoft Visual Studio 2005, this pop-up menu includes Add Web Reference. In this case, click Add Web Reference and proceed to Step 3.
    If you are using Microsoft Visual Studio 2008, proceed to Step 2.
  2. Click Advanced on the Add Service Reference dialog box, then click Add Web Reference on the Service Reference Settings dialog box.
  3. Type the following address in the URL text box: http://api.bing.net/search.wsdl?AppID=YourAppId&Version=2.2. For information about obtaining an AppId, see Bing Developer Center.
  4. Click Go.
  5. You can accept the default web reference name net.bing.api suggested in the Web reference name text box, or type your own name for the web reference in the text box. Click Add Reference to add the web reference to your project.

使用下面的代码进行测试

using System;
using System.Xml;// This using directive assumes that the project's default namespace is
// "ApiSamples" and the name of the Bing API web reference is
// "net.bing.api". Modify this using directive as necessary.
using ApiSample.net.bing.api;// Bing API 2.1 code sample demonstrating the use of the
// Web SourceType over the SOAP Protocol.
static class WebSample
{// Replace the following string with the AppId you received from the// Bing Developer Center.const string AppId = "你的AppId";static void Main(){// BingService implements IDisposable.using (BingService service = new BingService()){try{SearchRequest request = BuildRequest();// Send the request; display the response.SearchResponse response = service.Search(request);DisplayResponse(response);}catch (System.Web.Services.Protocols.SoapException ex){// A SOAP Exception was thrown. Display error details.DisplayErrors(ex.Detail);}catch (System.Net.WebException ex){// An exception occurred while accessing the network.Console.WriteLine(ex.Message);}}Console.Read();}static SearchRequest BuildRequest(){SearchRequest request = new SearchRequest();// Common request fields (required)request.AppId = AppId;request.Query = "msdn blogs";request.Sources = new SourceType[] { SourceType.Web };// Common request fields (optional)request.Version = "2.0";request.Market = "en-us";request.Adult = AdultOption.Moderate;request.AdultSpecified = true;request.Options = new SearchOption[]{SearchOption.EnableHighlighting};// Web-specific request fields (optional)request.Web = new WebRequest();request.Web.Count = 10;request.Web.CountSpecified = true;request.Web.Offset = 0;request.Web.OffsetSpecified = true;request.Web.Options = new WebSearchOption[]{WebSearchOption.DisableHostCollapsing,WebSearchOption.DisableQueryAlterations};return request;}static void DisplayResponse(SearchResponse response){// Display the results header.Console.WriteLine("Bing API Version " + response.Version);Console.WriteLine("Web results for " + response.Query.SearchTerms);Console.WriteLine("Displaying {0} to {1} of {2} results",response.Web.Offset + 1,response.Web.Offset + response.Web.Results.Length,response.Web.Total);Console.WriteLine();// Display the Web results.System.Text.StringBuilder builder = new System.Text.StringBuilder();foreach (WebResult result in response.Web.Results){builder.Length = 0;builder.AppendLine(result.Title);builder.AppendLine(result.Description);builder.AppendLine(result.Url);builder.Append("Last Crawled: ");builder.AppendLine(result.DateTime);DisplayTextWithHighlighting(builder.ToString());Console.WriteLine();}}static void DisplayTextWithHighlighting(string text){// Write text to the standard output stream, changing the console// foreground color as highlighting characters are encountered.foreach (char c in text.ToCharArray()){if (c == '\uE000'){// If the current character is the begin highlighting// character (U+E000), change the console foreground color// to green.Console.ForegroundColor = ConsoleColor.Green;}else if (c == '\uE001'){// If the current character is the end highlighting// character (U+E001), revert the console foreground color// to gray.Console.ForegroundColor = ConsoleColor.Gray;}else{Console.Write(c);}}}static void DisplayErrors(XmlNode errorDetails){// Add the default namespace to the namespace manager.XmlNamespaceManager nsmgr = new XmlNamespaceManager(errorDetails.OwnerDocument.NameTable);nsmgr.AddNamespace("api","http://schemas.microsoft.com/LiveSearch/2008/03/Search");XmlNodeList errors = errorDetails.SelectNodes("./api:Errors/api:Error",nsmgr);if (errors != null){// Iterate over the list of errors and display error details.Console.WriteLine("Errors:");Console.WriteLine();foreach (XmlNode error in errors){foreach (XmlNode detail in error.ChildNodes){Console.WriteLine(detail.Name + ": " + detail.InnerText);}Console.WriteLine();}}}
}

Bing API 2的体验相关推荐

  1. Java 实现在线翻译功能 调用微软Bing API

    下面是利用java程序实现翻译功能,调用微软Bing API 注意:代码中的keyId 需要自己申请... (1)首先去 http://code.google.com/p/microsoft-tran ...

  2. vue3.0 Composition API 上手初体验 使用 vue-router 构建多页面应用

    vue3.0 Composition API 上手初体验 使用 vue-router 构建多页面应用 前两讲,我们已经顺利的使用 vue3.0 将项目跑起来了.但是实在是过于简陋,目前我们几乎不可能开 ...

  3. 怎么申请 bing api key

    1:打开网址 https://login.live.com/ 注册帐号并登录(点击上图中的登录按钮即可),在新窗口点击下方的"立即注册"(有帐号的可以直接登录) 2:填写相关信息( ...

  4. 用Bing API接口实现同IP域名查询(Python版)

    在https://datamarket.azure.com/account/datasets这里注册帐号后申请一个免费的KEY,一个月可以查询5000次,其申请方法网上有很多教程了. import r ...

  5. 通过 Google 照片库 API 打造新体验

    文 / Google 照片开发主管 Jan-Felix Schmakeit 正如我们在 5 月发布的文章中所说,人们以多种不同方式创建和使用照片与视频,而我们认为应该让用户可以更轻松地在我们大家使用的 ...

  6. New Bing AI搜索引擎初体验-基于ChatGpt4

    今天看了一个有关三星想使用bing搜索来代替Google的新闻, 谷歌或被抛弃!ChatGPT 引爆手机市场新一轮洗牌:Android 手机销冠三星30亿美元大单欲改投 Bing 发现new bing ...

  7. kong api gateway 初体验

    Kong是一个可扩展的开源API层(也称为API网关或API中间件). Kong运行在任何RESTful API的前面,并通过插件扩展,它们提供超出核心平台的额外功能和服务. Kong最初是在Mash ...

  8. 微软 bing 壁纸 每日一图 bing api

    作者提供了一个在线的壁纸服务地址如下: http://47.111.254.61:8000/bingWpget请求或者粘贴到浏览器就可以获取最新的bing壁纸.谢谢. 如果地址不能使用了,请联系qq ...

  9. Flink Table Api SQL 初体验,Blink的使用

    概述 Flink具有Table API和SQL-用于统一流和批处理. Table API是用于Scala和Java的语言集成查询API,它允许以非常直观的方式组合来自关系运算符(例如选择,过滤和联接) ...

最新文章

  1. HDU2066(SPFA算法)
  2. 砝码问题之一(回头发现貌似多重背包)
  3. 自然语言处理——语言模型
  4. 工作日历计划javaweb_将你的日历与 Ansible 集成,以避免与日程冲突 | Linux 中国...
  5. RabbitMQ生产者和消费者Java实现
  6. 《SAP后勤模块实施攻略—SAP在生产、采购、销售、物流中的应用》——2.7 可配置制造...
  7. etc profile 的使用
  8. 关于python里面xlwt操作excel文件的时候去掉页眉页脚
  9. 网站关键词优化工具,网站关键词排名优化工具免费
  10. 易观CTO郭炜:开源,不是天才的甜点,而是勤奋者的盛宴
  11. js 跨浏览器tab页通信
  12. DNA sequence HDU 1560
  13. idm uestudio 20绿色版(文本代码编辑工具) v20.10.0.52
  14. MathType在word中的安装使用方法(要配合microsoft公式3.0才能使用)(ps:弄得不好可能造成word中Ctrl+V失灵)
  15. 计算机网络一课一文1000字,第一课 计算机网络及应用
  16. 1011 World Cup Betting
  17. [SpringMVC笔记] SpringMVC-16-拦截器入门
  18. 一半中国人已经大于35岁了,难道都没工作?
  19. Matlab的Simulink显示 ‘错误使用 slCustomizer.staticRefresh An error occurred during Simulink customization.‘
  20. 一周极客热文:Java 8简明教程

热门文章

  1. Vuebnb:一个用vue.js和Laravel构建的全栈应用
  2. 从源码开始运行Bitcoin Core
  3. Servlet第一篇【介绍Servlet、HTTP协议、WEB目录结构、编写入门Servlet程序、Servlet生命周期】...
  4. 最小生成树算法MST_kruskal算法
  5. 25个强大的 jQuery 砌体网页设计作品
  6. V神:随着时间的推移,我对链外数据L2越来越悲观
  7. 分片提升容量难度大,时间长,故而Vitalik提出使用BCH或者ETC作为以太坊数据层
  8. BCH交易量快速增长,年内增幅超比特币和莱特币
  9. 094、Swarm 中最重要的概念(Swarm01)
  10. java B2B2C 多租户电子商城系统-Spring Cloud Zipkin