gpt4 book ai didi

c# - 将 BingSearchContainer C# 类与搜索 API 结合使用

转载 作者:行者123 更新时间:2023-11-30 16:20:07 27 4
gpt4 key购买 nike

我创建了一个应用程序,我需要通过它使用 Bing 进行搜索。我安装了 Bing 库,并在搜索有关如何使用它的说明一两个小时后,我终于在 Microsoft 自己的文档中找到了一个示例(太棒了!他们制作了这样的东西!)。我的代码如下所示:

Uri rootUri = new Uri("https://api.datamarket.azure.com/Bing/SearchWeb/Web/");
BingSearchContainer bingContainer = new BingSearchContainer(rootUri);
bingContainer.Credentials = new NetworkCredential(AppID, AppID);
var SearchQuery = bingContainer.Web("site:" + domain + " inanchor:" + querystring, null, null, null, null, null, null, null);
var SearchResults = SearchQuery.Execute();

运行应用程序产生以下异常

A first chance exception of type 'System.Data.Services.Client.DataServiceQueryException' occurred in System.Data.Services.Client.dll
An unhandled exception of type 'System.Data.Services.Client.DataServiceQueryException' occurred in System.Data.Services.Client.dll
Additional information: An error occurred while processing this request.

中断发生在 bingContainer.Web(...) 行我正在按照 this example 中第 5 页的示例进行操作.

最佳答案

显然明确定义 SearchQuery 和 SearchResults 变量的类型解决了这样的问题:

DataServiceQuery<WebResult> SearchQuery = bingContainer.Web("site:" + domain + " inanchor:" + querystring, "en-us", null, null, null, null, null, null);
IEnumerable<WebResult> SearchResults;

关于c# - 将 BingSearchContainer C# 类与搜索 API 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14668335/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com