Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the BingSearchContainer C# class with the search API

Tags:

c#

bing-api

I've created an application through which I need to search using Bing. I installed the Bing libraries and after an hour or two searching for instructions on how to use this thing I finally found an example among Microsofts own documents (Amazing! They made such things!). 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 generates 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'm following the example on page 5 in this example.

like image 856
Steen Schütt Avatar asked Nov 29 '25 05:11

Steen Schütt


1 Answers

Appearently explicitly defining the type for 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;
like image 114
Steen Schütt Avatar answered Nov 30 '25 20:11

Steen Schütt