MVVM WCF Silverlight Factory Methods

MVVM WCF Silverlight Factory Methods

Old forum URL: forums.lhotka.net/forums/t/10287.aspx


Ziad posted on Wednesday, April 20, 2011

Hello,

I have a Factory method called GetTerritories, and it is found in the Model.

Remark: It is found in the if  ! SILVERLIGHT bloc.

My Question is :

How can I call this function from the view model? Can I use the BeginRefresh method in order to call it?

Note: I've configured all the WCF stuff

RockfordLhotka replied on Wednesday, April 20, 2011

The Silverlight ViewModelBase only supports async interaction with factory methods, and therefore assumes async factory methods.

Async factory methods are different from sync factory methods, because they require a callback parameter. Normally I implement the async factory methods for all code, and only the sync methods for .NET (so inside the # !SILVERLIGHT block).

If you have an async factory method on your business class, then the BeginRefresh method in the viewmodel will invoke that method.

Ziad replied on Wednesday, April 20, 2011

Thanks for your reply!

I'm somehow confused, my library is as the following:

1. library.Client  which is the silverlight library

2. library.Server which is the C# library

in this library, I've defined all the async functions in the Silverlight bloc and all the sync functions in the ! Silverlight bloc. 

How can I call the Remote DataPortal_Fetch() method, which is found in the ! Silverlight bloc, from the static method factory that is found in the Silverlight bloc? In other words, If I have the following:

#if Silverlight

public static void GetTerritories(EventHandler<DataPortalResult<Territories>> callback)
        {
            var dp = new DataPortal<Territories>();
            dp.FetchCompleted += callback;
            dp.BeginFetch();
        }

#else

protected void DataPortal_Fetch()

{

}

#endif

So I want my static factory method to call the Remote DataPortal_fetch and not the local one? how can I do this?

Thanks,

Ziad

Copyright (c) Marimer LLC