O'Reilly logo

Learning Microsoft Cognitive Services - Second Edition by Leif Larsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Searching the web

To be able to use Bing Web Search, we create a new class. Add a new file, called BingSearch.cs, to the Models folder.

We add a member of type BingWebRequest, which we create in the constructor:

    private BingWebRequest _webRequest; 
 
    public BingSearch() { 
        _webRequest = new BingWebRequest("API_KEY_HERE"); 
    } 

Create a new function called SearchWeb. This should accept two parameters, a string for the search query and a SafeSearch parameter. The function should be marked as async and return a Task<WebSearchResponse>. WebSearchResponse is a data contract we will learn more about in a bit:

public async Task<WebSearchResponse> SearchWeb(string query, SafeSearch safeSearch) { string endpoint = string.Format("{0}{1}&safeSearch={2} &count=5&mkt=en-US", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required