Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 针对Windows Phone的Bing API集成_C#_Windows Phone 8 - Fatal编程技术网

C# 针对Windows Phone的Bing API集成

C# 针对Windows Phone的Bing API集成,c#,windows-phone-8,C#,Windows Phone 8,我想不出问题出在哪里。我正在尝试集成bing搜索api,我引用了这里回答的类似问题。我的代码基本相同。但是我不能得到结果。我得到的例外情况是: 中发生“System.Net.WebException”类型的异常 System.Windows.ni.dll,并且在托管/本机 边界中发生“System.Net.WebException”类型的异常 System.Windows.ni.dll,并且在托管/本机 边界类型为“System.Data.Services.Http.WebException”的

我想不出问题出在哪里。我正在尝试集成bing搜索api,我引用了这里回答的类似问题。我的代码基本相同。但是我不能得到结果。我得到的例外情况是:

中发生“System.Net.WebException”类型的异常 System.Windows.ni.dll,并且在托管/本机 边界中发生“System.Net.WebException”类型的异常 System.Windows.ni.dll,并且在托管/本机 边界类型为“System.Data.Services.Http.WebException”的异常 发生在Microsoft.Data.Services.Client.WP80.DLL中,未处理 在托管/本机边界之前,类型为的异常 中出现“System.Data.Services.Http.WebException” Microsoft.Data.Services.Client.WP80.DLL,并且在 托管/本机边界类型的异常 发生“System.Data.Services.Client.DataServiceTransportException” 在Microsoft.Data.Services.Client.WP80.DLL中,并且在 托管/本机边界类型的异常 中出现“System.Data.Services.Client.DataServiceClientException” Microsoft.Data.Services.Client.WP80.DLL,并且在 托管/本机边界类型的异常 中出现“System.Data.Services.Client.DataServiceQueryException” Microsoft.Data.Services.Client.WP80.DLL,并且在 托管/本机边界类型的第一次意外异常 中出现“System.Data.Services.Client.DataServiceQueryException” Microsoft.Data.Services.Client.WP80.DLL

请帮帮我

using Bing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Services.Client;
using System.Net;


//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace MyApp
{
public partial class Page1 : PhoneApplicationPage
{
    public Page1()
    {
        InitializeComponent();
        Loaded += Page1_Loaded;
    }

    void Page1_Loaded(object sender, RoutedEventArgs e)
    {
        Main();


    }





    // Bing Search API code sample that demonstrates the News service operation.
    // Replace this value with your account key.
    //private const string AccountKey = "38d768UB4hTJgOhVpQGBIsqn5tNXi5PDlAWgnIAbjnY=";

    public void Main()
    {
        try
        {
            MakeRequest();
        }
        catch (Exception ex)
        {
            string innerMessage =
            (ex.InnerException != null) ?
            ex.InnerException.Message : String.Empty;
            string str = string.Format("{0}\n{1}", ex.Message, innerMessage);
            NewText.Text = str;
        }
    }
    public void MakeRequest()
    {
        const string AccountKey = "1U2M99wYcQb8gukg3Qk96uneDEZKx8GVDNeebXcabj4";

        // This is the query expression.
        string query = "rihanna";

        // Create a Bing container.
        string rootUrl = "https://api.datamarket.azure.com/Bing/Search";
        var bingContainer = new Bing.BingSearchContainer(new Uri(rootUrl));

        // The market to use.
        //string market = "en-us";

        // Get news for science and technology.
        //string newsCat = "rt_ScienceAndTechnology";

        // Configure bingContainer to use your credentials.
        bingContainer.Credentials = new NetworkCredential(AccountKey, AccountKey);

        // Build the query, limiting to 10 results.
        var newsQuery =
        bingContainer.News(query, null, null, null, null, null, null, null, null);

        //newsQuery = newsQuery.AddQueryOption("$top", 10);

        // Run the query and display the results.
        //var newsResults = newsQuery.Execute();

        try
        {
            newsQuery.BeginExecute(_onNewsQueryComplete, newsQuery);
        }
        catch (DataServiceQueryException ex)
        {
            throw new ApplicationException(
       "An error occurred during query execution.", ex);
        }
    }



    public void _onNewsQueryComplete(IAsyncResult newsResults)
    {

        DataServiceQuery<Bing.NewsResult> quer = newsResults.AsyncState as 
        DataServiceQuery<Bing.NewsResult>;




        var sanjay = new List<string>();

        foreach (var result in quer.EndExecute(newsResults))
        {
            sanjay.Add(
             result.Source);


        }

        NewText.Text += sanjay + "/n";
        //newmeth(j,sanjay);

    }









}


}
使用Bing;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Data.Services.Client;
Net系统;
//使用制度;
//使用System.Collections.Generic;
//使用System.Linq;
//Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Navigation;
使用Microsoft.Phone.Controls;
使用Microsoft.Phone.Shell;
名称空间MyApp
{
公共部分类第1页:PhoneApplicationPage
{
公共页1()
{
初始化组件();
加载+=第1页\u加载;
}
无效页面1_已加载(对象发送器,路由目标e)
{
Main();
}
//Bing搜索API代码示例,演示新闻服务操作。
//将此值替换为您的帐户密钥。
//私有常量字符串AccountKey=“38d768UB4hTJgOhVpQGBIsqn5tNXi5PDlAWgnIAbjnY=”;
公共图书馆
{
尝试
{
MakeRequest();
}
捕获(例外情况除外)
{
字符串内部消息=
(例如InnerException!=null)?
ex.InnerException.Message:String.Empty;
string str=string.Format(“{0}\n{1}”,例如Message,innerMessage);
NewText.Text=str;
}
}
public void MakeRequest()
{
常量字符串AccountKey=“1U2M99wYcQb8gukg3Qk96uneDEZKx8GVDNeebXcabj4”;
//这是查询表达式。
string query=“rihanna”;
//创建Bing容器。
字符串rootUrl=”https://api.datamarket.azure.com/Bing/Search";
var bingContainer=new Bing.BingSearchContainer(新Uri(rootUrl));
//要使用的市场。
//字符串market=“en-us”;
//获取科技新闻。
//string newsCat=“rt_ScienceAndTechnology”;
//配置bingContainer以使用您的凭据。
bingContainer.Credentials=新的网络凭据(AccountKey,AccountKey);
//生成查询,限制为10个结果。
var新闻查询=
bingContainer.News(查询,null,null,null,null,null,null,null);
//newsQuery=newsQuery.AddQueryOption(“$top”,10);
//运行查询并显示结果。
//var newsResults=newsQuery.Execute();
尝试
{
newsQuery.BeginExecute(\u onNewQueryComplete,newsQuery);
}
捕获(DataServiceQueryException ex)
{
抛出新的ApplicationException(
“查询执行期间发生错误。”,例如);
}
}
public void\u onNewsQueryComplete(IAsyncResult newsResults)
{
DataServiceQuery query=newsResults.AsyncState为
数据服务查询;
var sanjay=新列表();
foreach(query.EndExecute中的变量结果(newsResults))
{
桑杰,加上(
结果(来源);
}
NewText.Text+=sanjay+“/n”;
//newmeth(j,sanjay);
}
}
}

我曾多次尝试将bing API与WP8集成,但都没有成功,我不得不创建一个web API项目来处理请求,而不是从WP8项目创建请求