I'my trying to use the Bing Search API in my MVC project. What's odd is that when I run it through a console application I get the expected results, however when I try to run it online I get no results when I step into the program and look at the value for the variable imageResults. I do see a message TotalCount = 'imageResults.TotalCount' threw an exception of type 'System.InvalidOperationException.'
My controller is listed below.
namespace MusicMan.Controllers
{
public class BingSearchController : Controller
{
// GET: BingSearch
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string search)
{
var bingContainer = new Bing.BingSearchContainer(
new Uri("https://api.datamarket.azure.com/Bing/Search/"));
// Replaced the value with my account key.
var accountKey = "mykey";
// Configures bingContainer to use your credentials.
bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
// Build the query.
var imageQuery =
bingContainer.Image("xbox", null, null, null, null, null, null);
var imageResults = imageQuery.Execute();
return View();
}
}
}
Any help on why it works as a console app but not MVC would be greatly appreciated.