Accessing Business Object Methods from Silverlight
I'm new to Sliverlight and RIA Services and I've hit a bit of a wall.
I have a Silverlight app that needs to access our DAL to get our custom objects to populate the UI. I set up the RIA service. In my web app, I have added a DomainService and it calls the DAL service to get the data back.
I have a separate project that houses our business objects and the DomainService returns this an list of these objects. In the business objec开发者_JAVA技巧t, I have added the Key attribute to the ID property.
Everything is working fine. I can call the service, I can get the list of objects. I can see them in my Silverlight app and I can see all the properties of my objects.
The only thing I can't figure out is how to access the methods. I have a few methods in my Business object that I need to access in my Silverlight app, but it doesn't appear as though the method is exposed.
Is there a way that I can access these methods from the class? Or do I have to write a wrapper in my DomainService object that will call this method for me? I'd rather the first really.
Any help would be greatly appreciated. This has been blocking for far too long now.
Sounds like you are pretty close.
From the way you describe it sounds like the business object classes aren't instantiated. You need to put "stub" methods into the web project (DomainService) that allows Silverlight to use the methods on the business object.
In your DomainService class:
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using XYX.YourBusinessClassLibrary; <-- need reference in web app
[EnableClientAccess()]
public class linkdirectoryDS : DomainService
{
public IEnumerable<Category> GetCategories()
{
Category cat = new Category();
return cat.Retrieve();
}
}
About the GetCategories method:
It must be a method and not a property.
Must return one of:
- A single entity
- An IEnumerable where T is the entity
- An IQueryable where T is the entity
The method can have any name, parameters.
Maybe I just described what you didn't want to do... if so I apologize.
精彩评论