views:

40

answers:

0

I'm putting together a series of web parts for a Sharepoint 2010 deployment - a few upgrades (from 2007) as well as a few new ones. I'm attempting to develop all the parts to perform data access server-side via a WCF service (namely, WCF RIA Services in this case). Basic synchronous databinding works great (for example):

SomeGrid.DataSource = MyDataService.GetData().RootResults;

In theory, if this Grid was part of the only web part on the page, this would be sufficient. However, many of the web parts I'm developing are going to be part of a user "dashboard," so waiting on a synchronous call for each web part to databind is not going to be an acceptable option. As such, async service calls would be ideal:

MyDataService.GetDataCompleted += new EventHandler<MyDataService.GetDataArgs>(MyDataService_GetDataCompleted);
MyDatService.GetDataAsync();

with the appropriate event handler of course. That said, when I attempt to run this, I get the following error:

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.

Everything I've found so far says the Async=True setting needs to be set in the Page tag - which the Sharepoint page parser chokes on. So the first question is simple - is there any way to do an async service call in a Visual Web Part?

Outside of that, I can only identify two other alternatives:

  1. Ditch WCF as my data access point for the Web Part and go back to using ObjectDataSources. Upside is that I save basically all my existing work, but the major downside is that I completely lose the client-independent re-usability that a WCF service provides (i.e., I would have to develop and maintain separate code bases for multiple applications).
  2. Eliminate all server-side service calls and make everything client-side service calls. Upside is that this might actually be the only way to do async service calls in Sharepoint, but the major downside is that I lose all the server-side development already done on my existing web parts.

Is there a better alternative that I'm can't see? Or is there an easy way to do Async calls from Visual Web Parts/