我建立使用標準的OData客戶端: Microsoft.Data.Services.Client.Portable 的Windows 8 VS2013錯誤訪問WCF服務
我添加了一個服務參考項目(TMALiveData)授權。現在我想要檢索數據。我正在使用下面的代碼,但是當我這樣做時,我在最後一個循環中得到一個空指針引用。
的代碼是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Services.Client;
namespace testLSconWithMSv2
{
public class testLSCon
{
static string mResult;
public static string result { get { return mResult; } }
public static void testREADLiveConnection()
{
Uri tmaLiveDataRoot = new Uri("https://xxx.azurewebsites.net/xxx.svc/");
TMLiveData.TMALiveData mLiveData = new TMLiveData.TMALiveData(tmaLiveDataRoot);
mResult = null;
DataServiceQuery<TMLiveData.JobType> query = (DataServiceQuery<TMLiveData.JobType>)mLiveData.JobTypes.Where(c => c.IsActive == true);
mResult = "Trying to READ the data";
try
{
query.BeginExecute(OnQueryComplete, query);
}
catch (Exception ex)
{
mResult = "Error on beginExecute: " + ex.Message;
}
}
private static void OnQueryComplete(IAsyncResult result)
{
DataServiceQuery<TMLiveData.JobType> query = result as DataServiceQuery<TMLiveData.JobType>;
mResult = "Done!";
try
{
foreach (TMLiveData.JobType jobType in query.EndExecute(result))
{
mResult += jobType.JobType1 + ",";
}
}catch (Exception ex)
{
mResult = "Error looping for items: " + ex.Message;
}
}
}
}
有什麼明顯的是我做錯了嗎? 我已經基於MS例如在方法:How to Execute Async...
哪個對象爲空? –