I am using the following code to get more than 50 results from a Bing image search using the Bing Search Container for the Bing API. My problem is that when I try and execute another query (query.Excecute()
) after changing the off-set to get the next 50 results ("$skip", 50)
I get the following error:
A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.Data.Services.Client.dll
I can't figure out how to do another query. Just to re-iterate this occurs when the when the for loop executes the second time. This happens on this line var results = query.Execute();
and when it tries the query.
void bingSearch(string searchTerm)
{
try
{
imageSet = new List<Bing.ImageResult>();
const string bingKey = "[key]";
var bing = new BingSearchContainer(
new Uri("https://api.datamarket.azure.com/Bing/Search/")) { Credentials = new NetworkCredential(bingKey, bingKey) };
var query = bing.Image("\"" + searchTerm + "\"" + "(" + site1 + ")", null, null, null, null, null, ImageFilters);
Debug.Print("Full Search: " + query.ToString());
int length = 3;
int resultsPage = 0;
for (int i = 0; i < length; i++)
{
query = query.AddQueryOption("$top", 50);
query = query.AddQueryOption("$skip", resultsPage);
var results = query.Execute();
int index = 0;
foreach (var result in results)
{
imageSet.Add(result);
Debug.Print("URL: " + imageSet[index].Title);
index++;
}
resultsPage = resultsPage + 50;
Debug.Print("Getting Next Page: " + resultsPage);
}
Debug.Print("Results: " + imageSet.Count);
}
catch
{
Debug.Print("Error");
}
}