Using C # BingSearchContainer class with search API

I created an application that I need to search through with Bing. I installed the Bing Libraries, and after an hour or two, looking for instructions on how to use this thing, I finally found an example among Microsoft's own docs (Amazing! They did such a thing!). My code looks like this:

Uri rootUri = new Uri("https://api.datamarket.azure.com/Bing/SearchWeb/Web/");
BingSearchContainer bingContainer = new BingSearchContainer(rootUri);
bingContainer.Credentials = new NetworkCredential(AppID, AppID);
var SearchQuery = bingContainer.Web("site:" + domain + " inanchor:" + querystring, null, null, null, null, null, null, null);
var SearchResults = SearchQuery.Execute();

      

Running the application throws the following exception

A first chance exception of type 'System.Data.Services.Client.DataServiceQueryException' occurred in System.Data.Services.Client.dll
An unhandled exception of type 'System.Data.Services.Client.DataServiceQueryException' occurred in System.Data.Services.Client.dll
Additional information: An error occurred while processing this request.

      

The break occurs on the line with bingContainer.Web(...)

I am following the example on page 5 in this example .

+3


source to share


1 answer


Obviously, explicitly defining the type of the SearchQuery and SearchResults variables fixed the problem as such:



DataServiceQuery<WebResult> SearchQuery = bingContainer.Web("site:" + domain + " inanchor:" + querystring, "en-us", null, null, null, null, null, null);
IEnumerable<WebResult> SearchResults;

      

+3


source







All Articles