New Posts New Posts RSS Feed: Async ServerMethod returning Task<T>
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Async ServerMethod returning Task<T>

 Post Reply Post Reply
Author
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Topic: Async ServerMethod returning Task<T>
    Posted: 15-Jul-2013 at 11:37am
Hi,

I'm creating a server method that I would like to be an async method that return a bool value.

[AllowRpc]
public async static Task<bool> SendEmail(IPrincipal principal, EntityManager entityManager, params Object[] args)
{
 
}
But I receive this error:
An error occurred while communicating with the server.  A common cause for this error is a return type from the invoked method which is either not serializable or not marked as a known type.

I understand that Task<T> is not a valid return type for a server method and I can create SendEmail without async, but I have a bunch of async business logic implemented and I would take advantage of that.

What do you suggest?

Regards.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 15-Jul-2013 at 3:00pm
DevForce allows only the synchronous signature for its remote server methods.  To call them asynchronously from a client app you can use the EntityManager.InvokeServerMethodAsync call.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 15-Jul-2013 at 3:06pm
cefernan,

Remote server methods must conform with the ServerMethodDelegate type:


public delegate object ServerMethodDelegate(IPrincipal principal, EntityManager serverEntityManager, params object[] args)


The server method will execute synchronously in the server, but you can invoke it asynchronously on the client:


var op = await entityManager.InvokeServerMethodAsync(serverMethod, startDate, endDate);


You can find this info at http://drc.ideablade.com/devforce-2012/bin/view/Documentation/rsmc-query.
You will also find a sample at http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-remote-server-method
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 16-Jul-2013 at 11:14am
I got it, I was asking because I want to use others existent async methods inside my server method, in this case will be necessary to use await. Consequently, my server method needs to be async. 

What I need to do is create a synchronous equivalent method for each existent asynchronous method.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jul-2013 at 7:39am
You can use Task.WaitAll to achieve this in your synchronous server method

Edited by smi-mark - 17-Jul-2013 at 7:39am
Back to Top
cefernan View Drop Down
Groupie
Groupie


Joined: 13-Jul-2012
Posts: 70
Post Options Post Options   Quote cefernan Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jul-2013 at 9:34am
You are right, Mark.

Thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down