jump to navigation

Trick for solving WCF RIA Services issue.. July 23, 2010

Posted by Jose Luis Latorre Millas in Business Applications, Silverlight, WCF RIA Services.
3 comments

I am having the following issue: Sometimes, when I am issuing a DomainService call using WCF RIA Services, I got the callback right but the loadoperation I have assigned has no results, meaning no entities are returned and the “IsComplete” property is false. 

The following code resumes what I am doing, including the LoadOperation definition, the calling function and the callback function: 

LoadOperation lo; 

private void CallDomainService(){ 

DomainContext dc =  new DomainContext(); 

lo = dc.Load(dc.GetDataQuery()); 

lo.Completed += new EventHandler(lo_Completed); 

} 

And it executes well and calls properly lo_completed… 

void lo_Completed(object sender, EventArgs e){ 

     if ((lo != null) && (lo.IsComplete == true)){

      if ((lo.Entities !=null) && (lo.Entities.Count() >= 1))         //Get the returned entity or whatever..

   }

} 

The issue is that I am getting properly the details of the load Operation, but some random times, it does not return the object properly, it is not null but its .IsComplete property is False and the Entities collection is empty, though that it has had been processed properly by the server.

The trick or workaround here is to get, in this exact case, the loadoperation from the server, which is a reference to the right load operation. The code should be like this:

LoadOperation<EntityType> lo2 = (LoadOperation<EntityType>)sender;

if ((lo2.IsComplete) && (lo2.Entities.Count() >= 1)) {

   EntityType Entity = lo2.Entities.First();

 

}

And with this, problem solved.

Are you having this random issue or others? anybody found why this is happening?

Follow

Get every new post delivered to your Inbox.