Working with BingSearchContainer.. But cant find .Web() method like in the tutorials..?

StackOverflow https://stackoverflow.com/questions/19543606

  •  01-07-2022
  •  | 
  •  

Question

Im trying to use the Bing search Api according to a tutorial provided by Microsoft. It looks like this:

        string query = "Xbox Live Games";
        string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
        var bingContainer = new BingSearchContainer(new Uri(rootUrl));
        string market = "en-us";
        bingContainer.Credentials = new NetworkCredential("AccountKey", "AccountKey");
        var webQuery = bingContainer.Web(query, null, null, market, null, null, null, null);
        webQuery = webQuery.AddQueryOption("$top", 10);
        var webResults = webQuery.Execute();
        foreach (var result in webResults)
        {
            Console.WriteLine("{0}\n\t{1}", result.Title, result.Url);
        }   

I have added the api as a service reference

enter image description here

And everything looks fine to me! But why oh why cant I use . .Web() method?? enter image description here

Was it helpful?

Solution

Your mistake is adding the url in the sample as a Service reference, instead of adding the proxy class which you can get from Microsoft. If you're looking at the same bing API tutorial I am, it says above the code sample:

Creating a .NET Framework C# application is pretty easy. Most of the work that you need to do is handled for you by the Microsoft .NET Framework C# Service Proxy Class Library. You can download the service proxy for the Bing Search API by clicking the following link: https://datamarket.azure.com/dataset/explore/getproxy/5ba839f1-12ce-4cce-bf57-a49d98d29a44.

So, you need to download the proxy class and use that, not add the bing api as a service reference. Once you add the proxy class to your project, the sample will find the bingContainer.Web method and compile just fine:

Proxy Class

Hopefully this also goes without saying, but you'll need a valid account key - NetworkCredential("AccountKey", "AccountKey"); isn't going to cut it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top