开发者

How can I bind to an Invoke operation on a DomainService?

I'm tinkering with RIA Services and I've created a DomainService and I'm 开发者_如何学JAVAable to bind that to grids/dataforms and the like... but for the life of me I can't see how I can call custom methods on that DomainService. I've created a method like this:

[Invoke]
public IEnumerable<string> GetCities()
{
    return new List<string>() { "some city" };
}

I want to be able to bind the items collection of a combobox to that method (one-way).

In the silverlight page, there is a peopleDomainService object that is created as a resource when adding controls to the page that is used for binding. But nowhere on it can I find any of my custom methods.


The way you are describing not seeing the method makes me wonder if you have created an instance of peopleDomainService or if you are just referring to the class definition that was automatically put into the XAML.

Something like this should work fine, as long as you've rebuilt the .Web project.

peopleDomainService ldCTX = new peopleDomainService();
var query = ctx.GetCities();
ldCTX.Load( query, GetCities_Loaded, null );

And add your GetCities_Loaded event to handle the result.


Assuming your invoke method is in the FooDomainService you'd call it so:

fooDomainServiceInstance.Context.GetCities( (op) =>
{
  if (op.HasError)
  {
    // Handle error.
  }
  else
  {
   var data = ( op as InvokeOperation<IEnumerable<string>> ).Value;
   // Do something with the data...
  }
}, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜