Quickstart: Use the Bing Entity Search .NET client library
Use this quickstart to begin searching for entities with the Bing Entity Search client library for C#. While Bing Entity Search has a REST API compatible with most programming languages, the client library provides an easy way to integrate the service into your applications. The source code for this sample can be found on GitHub.
Prerequisites
Any edition of Visual Studio 2017 or later.
The Json.NET framework, available as a NuGet package.
If you are using Linux/MacOS, this application can be run using Mono.
The Bing News Search SDK NuGet package. Installing this package also installs the following:
- Microsoft.Rest.ClientRuntime
- Microsoft.Rest.ClientRuntime.Azure
- Newtonsoft.Json
To add the Bing Entity Search client library to your Visual Studio project, use the Manage NuGet Packages option from Solution Explorer, and add the Microsoft.Azure.CognitiveServices.Search.EntitySearch
package.
Create and initialize an application
Create a new C# console solution in Visual Studio. Then add the following into the main code file:
using System; using System.Linq; using System.Text; using Microsoft.Azure.CognitiveServices.Search.EntitySearch; using Microsoft.Azure.CognitiveServices.Search.EntitySearch.Models; using Newtonsoft.Json;
Create a client and send a search request
Create a new search client. Add your subscription key by creating a new
ApiKeyServiceClientCredentials
.var client = new EntitySearchClient(new ApiKeyServiceClientCredentials("YOUR-ACCESS-KEY"));
Use the client's
Entities.Search()
function to search for your query:var entityData = client.Entities.Search(query: "Satya Nadella");
Get and print an entity description
If the API returned search results, get the main entity from
entityData
.var mainEntity = entityData.Entities.Value.Where(thing => thing.EntityPresentationInfo.EntityScenario == EntityScenario.DominantEntity).FirstOrDefault();
Print the description of the main entity.
Console.WriteLine(mainEntity.Description);
Next steps
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기