2011-11-19 93 views
1

我正在嘗試將Bings API API數據導出。我已經將SOAP服務添加到了我的解決方案中,並且確實收到了結果。問題是,顯示的結果總是相同的,不管我已經設置了request.Web。當我搜索時,它顯示98個結果,所以它不是缺乏結果。Bings Search API總是返回相同的10個結果

 BingService soapClient = new BingService(); 

     string resp = string.Empty; 
     SearchRequest request = new SearchRequest(); 
     request.AppId = ConfigurationManager.AppSettings["BingKey"]; 
     request.Sources = new BingLiveSearchService.SourceType[] { SourceType.Web }; 
     request.Query = query; 
     request.Web = new BingLiveSearchService.WebRequest { Count = 10, Offset = 10 }; 

     var response = soapClient.Search(request); 
     if (response.Web != null && response.Web.Total > 0) 
     { 
      resp += "TOTAL COUNT:"+response.Web.Total +"<br/><br />"; 
      foreach (var item in response.Web.Results) 
      { 
       resp += "<div style='padding-bottom:10px;'>" + item.Title + "</div>"; 
      } 

     } 

回答

2

這是奇怪這些API,但你需要指定的變量設置爲true,所以加

request.Web.CountSpecified = true; 
request.Web.OffsetSpecified = true; 
+0

如果我指定的值,爲什麼還規定我已經指定,怪異:)一個奇怪的事情是,如果我做了最初的搜索,沒有偏移它說98結果,如果我然後設置偏移量爲10,它說有18個結果。你知道爲什麼發生這種情況嗎? – Dofs

+1

其bing我的朋友,它的冰雹:) –

+0

我有同樣的問題我只有41結果爲一個簡單的單詞'遊戲'我正在使用json ..請幫我解決這個問題。我問過一個問題http://stackoverflow.com/questions/8637051/bing-api-returns-41-results-for-simple-word-game –

2

看一看WebRequest.Count。看起來您可以配置通過此返回的結果數量。

編輯: Here's一個例子,其中.Count被使用。