【问题标题】:Data not getting loaded from WCF RIA to SIlverlight MainPage.xaml.cs数据未从 WCF RIA 加载到 SIlverlight MainPage.xaml.cs
【发布时间】:2013-12-23 13:42:57
【问题描述】:

我创建了一个 Silverlight 应用程序,我在其中使用 WCF RIA 服务。 我的 MainPage.xaml.cs 无法从域服务中获取数据。域服务中的方法是

public IQueryable<Measurement> GetMeasurements()
{
    return this.ObjectContext.Measurements;
}

MainPage.xaml.cs 中的代码如下

EntityQuery<Measurement> query = from p in service.GetMeasurementsQuery() select p;

LoadOperation<Measurement> measurement = service.Load(query);

请告诉我一些意见和建议。

【问题讨论】:

  • 如果您描述您预期实际正在发生什么,您将获得更好的帮助。正如您所描述的,我没有看到您的代码有问题。

标签: c# silverlight wcf-ria-services


【解决方案1】:

对 RIA 服务最常见的误解是期望 Web 服务调用是同步的。实际上,Web 服务调用是异步发生的。您不能期望在 Load() 调用之后立即加载结果。

// creates a query object. It is the equivalent of 
// "SELECT ... FROM ..." as a string. It doesn't actually
// execute the query.
EntityQuery<Measurement> query = 
  from p in service.GetMeasurementsQuery() select p;

// sends the query to the server, but the server doesn't
// return a result in the LoadOperation. The LoadOperation
// will call you back when it is completed.
LoadOperation<Measurement> measurement = service.Load(query);

// when results are available, MeasurementLoaded is called
measurement.Completed += MeasurementLoaded;

// WARNING: do not have any code that expects results here.
// var myMeasurements = service.Measurements;


public void MeasurementLoaded(object sender, EventArgs eventArgs)
{
   // you can use service.Measurements now.
   var myMeasurements = service.Measurements;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多