1

大家好,我正在使用 WCF RIA 服务我有域服务,我在其中编写了这个方法

public List<int> GetActionIDs() 
    {
        return (from d in ObjectContext.actions select d.id).ToList();
    }

我如何在客户端获取此列表?这不起作用:

List<int> = db.GetActionIDs();

有什么建议么?

4

2 回答 2

1

首先,您应该阅读RIA 服务手册,因为您没有意识到 Silverlight 中的服务调用是异步的。

在你的情况下,你应该

在服务中添加InvokeAttribute到您的操作:

[Invoke]
public List<int> GetActionIDs() 
{
    return (from d in ObjectContext.actions select d.id).ToList();
}

然后,所有调用DomainContext都是异步的,因此您可以在回调中获得结果:

db.GetActionIDs(operation =>
                {
                  //TODO: check the operation object for errors or cancellation

                  var ids = operation.Value; // here's your value

                  //TODO: add the code that performs further actions
                }
                , null);
于 2011-11-30T08:08:12.893 回答
0

域服务内部

[Query]    
public List<Action> GetActionIDs()     
 {         
   List<Action> result =  (  
                           from a in ObjectContext.actions                                     
                            select new action                                   
                             {                        
                                ID = a.ID
                             }
                        ).ToList(); 
   return result ;
 }

银光

DomainService1 DS = new  DomainService1();
LoadOperation<Action> LoadOp = Ds.Load(Ds.GetActionIDsQuery());

LoadOperation.Completed += new EventHandler((s,e)=>{
   foreach (Action item in LoadOp.Entities)
   {
   }
});
于 2011-11-30T07:17:26.057 回答