Print Page | Close Window

Async ServerMethod returning Task<T>

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4225
Printed Date: 28-Mar-2025 at 1:34am


Topic: Async ServerMethod returning Task<T>
Posted By: cefernan
Subject: Async ServerMethod returning Task<T>
Date 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.



Replies:
Posted By: kimj
Date 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.


Posted By: sbelini
Date 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 - 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 - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/code-sample-remote-server-method


Posted By: cefernan
Date 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.


Posted By: smi-mark
Date Posted: 17-Jul-2013 at 7:39am
You can use Task.WaitAll to achieve this in your synchronous server method


Posted By: cefernan
Date Posted: 17-Jul-2013 at 9:34am
You are right, Mark.

Thanks!



Print Page | Close Window