We've got an internal HTTP REST (using webapi) service. I want to wrap that with a CSLA object in Silverlight so I get the fancy databinding and business rule tracking. I've code running that can do the requests. So my question is, Can I make silverlight csla use a "local" dataportal? The local dataportal just makes webapi commands. It is working great on my full .NET desktop app.
Yes, you can do that in Silverlight (and WinRT).
Pre-Csla 4.5 you must specify ProxyModes.LocalOnly on the DataPortal call.
From Csla 4.5 you can use Task<T> and and the [RunLocal] attribute pretty much the same as in .NET.
I've got the dataportal_fetch method to execute locally but now the callback won't fire. It is like I'm not getting a FetchCompleted event. I'm using 4.3.13. Here is how I'm calling the local only portal. Is there another/better way to do it?
public static void GetMachineList(EventHandler<DataPortalResult<MachineList>> callback)
{
var dp = new DataPortal<MachineList>(DataPortal.ProxyModes.LocalOnly);
dp.FetchCompleted += callback;
dp.BeginFetch();
}
It is your responsibility to call the callback funtion from within the DataPortal_Fetch method after the async data access is completed.
Look at the SL samples for CSLA 4.3.13.
In a .NET app you typically do sync DataAccess so the DataPortal will make the callback for you.
In a SL app the DataAccess is async so your DataAccess methods must accept a callback parameter and is responsible for making the callback.
Somewhat similar to this:
public void DataPortal_Fetch(object criteria Csla.DataPortalClient.LocalProxy<businessObject>.CompletedHandler handler)
{
// Call webservice asynchronously,
// and make sure to always invoke handler when completed or error!!
}
I can do that. When doing SL apps in the past that called WCF dataportal I used the .FetchCompleted event and then raised by callback from there. So the FetchCompleted apparently doesn't fire when you do a local running dataportal. I also can't find anyway to raise it myself. I can convert my dataportal calls to take a callback and do it there. Thanks!
That worked! I never did that on a remote dataportal with SL+WCF before. Thanks again!
That worked for fetch and delete. How do I get the insert and update to work? I just call Save() on the Editable root object and I can errors about a missing ServiceReferences.ClientConfig file. I had one of these in my last SL project talked to WCF. Do I need to put something in here for a local dataportal or is that set somewhere else?
Look for a Save/Delete method that accept ProxyMode as parameter.
I don't see a BeginSave() overload that takes a proxy mode. It looks like I can override the BeginSave in my business object class. I could use the same type of code I'm using to call delete locally but install call update (I don't see an insert, so I don't know how that will work). Is there another way or is the BeginSave override the way to go in 4.3?
Hmm,
Yes, it seems we have missed on that one - however you can add these overloads yourself to your baseclasses or business objects.
If you do no want to mix remote and local proxy - ie: only run local proxy you only need to set:
Csla.DataPortal.ProxyTypeName == "Local";
and this will force SL DataPortal to only use local proxy mode.
That did it! Thanks again for all of your help!
Jon
Copyright (c) Marimer LLC