Search code examples
silverlightwcfwcf-ria-servicesdomainservices

How to return List<int> from domain service


Hello guys im using WCF RIA Services i have domain services where i wrote this method

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

How i can get this List in client side? This does not works :

List<int> = db.GetActionIDs();

any suggestions?


Solution

  • First of all, you should read the RIA Services manual, because you don't realize that service calls in Silverlight are asynchronous.

    In your case, you should

    Add InvokeAttribute to your operation in the service:

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

    Then, all calls to DomainContext are asynchronous, so you get your results in the callback:

    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);