成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

必應(yīng)Bing API實(shí)戰(zhàn)初體驗(yàn)

開發(fā) 開發(fā)工具
Bing正式發(fā)布沒幾天,除了功能和搜索結(jié)果外,作為開發(fā)者來說,我們關(guān)心的還有Bing API啥時(shí)候能出。周末瀏覽MSDN網(wǎng)站時(shí),發(fā)現(xiàn)Bing Service已經(jīng)上線了,本文為大家做一個(gè)初步介紹。

Bing提供的API很豐富,除了搜索外,還增加了廣告Ad、圖片、新聞、Phonebook、拼寫和視頻的搜索。而訪問協(xié)議有三種:JSON, XML和SOAP。JSON協(xié)議用于AJAX應(yīng)用,XML用于Silverlight應(yīng)用,SOAP用于傳統(tǒng)的.NET等強(qiáng)類型程序。可見,微軟在推出API方面還是很有效率的。

使用Bing API的***步,是去Bing Developer Center上申請(qǐng)一個(gè)AppId,每個(gè)應(yīng)用應(yīng)該使用一個(gè)單獨(dú)的AppId。Bing Developer Center的網(wǎng)址是:http://bing.com/developers 。在頁(yè)面里先用Live ID登錄,然后選擇Get a new App ID,填寫一些基本信息,然后你就會(huì)得到一串很長(zhǎng)的AppId。需要注意的是,Bing還有一個(gè)網(wǎng)址是http://www.bing.com/developer/,估計(jì)是為1.1版本準(zhǔn)備的,現(xiàn)在還不能申請(qǐng)AppId。大家一定要分清楚。

接下來,我們?cè)赩isual Studio 2008里創(chuàng)建一個(gè).NET應(yīng)用。在Project菜單里選擇Add Service Reference,在彈出對(duì)話框的Address文本框里填入:

http://api.search.live.net/search.wsdl?AppID=yourAppId

注意:AppID=后要填寫你申請(qǐng)到的AppId.

BingApi

在找到LiveSearchService的引用后,將其添加到我們的工程中。接下來,我根據(jù)PhoneBook和WebSearch兩個(gè)例子寫了DEMO,更多例子可以參考:

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

需要提醒的是,可能是文檔沒有更新,Bing API的類名稱還會(huì)發(fā)生變化。我發(fā)現(xiàn)在2009年6月8日導(dǎo)出的引用中,LiveSearchService的名稱變成了LiveSearchPortTypeClient。Web Search的代碼如下:

   privatevoid button2_Click(object sender, EventArgs e)
        {
            // LiveSearchService implements IDisposable.
            using (LiveSearchPortTypeClient service = new LiveSearchPortTypeClient())
            {
                try
                {
                    SearchRequest request = BuildRequestWeb();

                    // Send the request; display the response.
                    SearchResponse response = service.Search(request);
                    DisplayResponseWeb(response);
                }
                catch (System.Net.WebException ex)
                {
                    // An exception occurred while accessing the network.
                    Console.WriteLine(ex.Message);
                }
            }
        }

        private SearchRequest BuildRequestWeb()
        {
            SearchRequest request = new SearchRequest();

            // Common request fields (required)
            request.AppId = AppId;
            request.Query = "馬寧";
            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 = 30;
            request.Web.CountSpecified = true;
            request.Web.Offset = 0;
            request.Web.OffsetSpecified = true;
            request.Web.Options = new WebSearchOption[]
            {
                WebSearchOption.DisableHostCollapsing,
                WebSearchOption.DisableQueryAlterations
            };

            return request;

        }

        private void DisplayResponseWeb(SearchResponse response)
        {
            // Display the results header.
            listBox1.Items.Add("Bing API Version " + response.Version);
            listBox1.Items.Add("Web results for " + response.Query.SearchTerms);
            listBox1.Items.Add(string.Format("Displaying {0} to {1} of {2} results",
                response.Web.Offset + 1,
                response.Web.Offset + response.Web.Results.Length,
                response.Web.Total));

            // 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);

                listBox1.Items.Add(builder.ToString());
                Console.WriteLine();
            }
        }
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

從代碼上來看,很簡(jiǎn)單,先創(chuàng)建一個(gè)LiveSearchPortTypeClient的對(duì)象,然后,創(chuàng)建SearchRequest對(duì)象,在Request里需要設(shè)置的是AppId,Query和Sources。AppId不用多說了,Query里填我們要查的關(guān)鍵字,Sources里指定SourceType,我們這里指定的是SourceType.Web。

查詢關(guān)鍵字

將SearchRequest參數(shù)傳遞給LiveSearchPortTypeClient的Search方法,會(huì)返回一個(gè)SearchResponse的對(duì)象,里邊包含我們的搜索結(jié)果。結(jié)果會(huì)包含在response.Web.Results對(duì)象里,最主要的參數(shù)是Title、Description和Url。

***的運(yùn)行結(jié)果就是這樣的了:

運(yùn)行結(jié)果

Bing的好壞還需要時(shí)間檢驗(yàn),但是Bing API和Google API應(yīng)該差不多,而且考慮了不同用戶的需求,這也許就是軟件公司和互聯(lián)網(wǎng)公司不一樣的地方。同時(shí)推出的還有Bing Map API,改天試一下。

【編輯推薦】

責(zé)任編輯:彭凡 來源: cnblogs
相關(guān)推薦

2009-06-10 10:45:41

Flash BuildBingScala

2013-06-27 08:59:00

微軟Bing

2013-12-12 10:46:22

2013-12-12 11:33:31

iOS 7API

2009-08-01 09:06:35

UbuntuOneLinux開源操作系統(tǒng)

2009-03-09 15:12:39

XenServer安裝

2009-06-02 09:22:02

BingGoogle搜索

2020-09-28 06:57:39

Node.jsGraphQLAPI

2023-07-15 08:01:38

2010-11-22 10:31:17

Sencha touc

2011-05-30 15:12:10

App Invento 初體驗(yàn)

2009-11-30 10:09:02

谷歌Chrome OS

2011-08-02 10:26:59

iOS 多線程 線程

2011-11-01 10:30:36

Node.js

2013-06-08 10:15:29

Outlook 201Outlook 201

2011-09-15 15:03:10

2010-12-13 11:39:39

2025-03-18 07:30:41

2017-09-05 05:55:24

AWS ES集群大數(shù)據(jù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: se婷婷| 韩日在线观看视频 | 一区二区三区小视频 | 久久精品国产99国产精品 | 欧美日一区| 色婷婷久久久久swag精品 | 蜜月va乱码一区二区三区 | 亚洲欧美一区二区三区国产精品 | 免费观看一级毛片 | 亚洲a人| 日韩毛片中文字幕 | 在线视频国产一区 | 日韩中文字幕在线观看 | 超碰97免费观看 | 91精品国产91久久久久久吃药 | 亚洲精品中文字幕在线观看 | 国产精品99久久久久久动医院 | 欧美成人久久 | 99国产精品视频免费观看一公开 | 欧美在线视频网 | 免费一级片 | av中文字幕在线播放 | 99亚洲精品 | 日韩视频在线一区二区 | 亚洲高清成人在线 | 国产成人精品999在线观看 | 中文字幕亚洲免费 | 一区免费观看 | 国产一区二区 | 一级片视频免费 | 中文字幕一区二区三区四区五区 | 日韩一区不卡 | 久久国产精99精产国高潮 | 亚洲日韩视频 | 少妇一级淫片免费播放 | 亚洲精品小视频在线观看 | 久久久性色精品国产免费观看 | 免费久久99精品国产婷婷六月 | 亚洲伊人久久综合 | 91素人 | 欧美一区二 |