Thursday, September 1, 2011

WCF RIA and custom methods

There may be times where-in you will have to add some custom coded methods along with the auto generated EF wrapper methods. You may be wondering how to do. Don't worry.. RIA provides support for that and is very simple. Follow these steps to get this work;

Server-side

In the Domain service class, decorate the custom methods with the [Invoke] attribute. Job done!!

[Invoke]
public string SayHello ()
{
        return "Hello";
}

Client-side

This is how you can access the RIA custom methods;

HelloDomainServiceContext ds = new HelloDomainServiceContext();
ds.SayHello( (p) => {var result = p.Value;}, null);