MVVM Silverlight Not refreshing afte fetching type of BusinessListBase

MVVM Silverlight Not refreshing afte fetching type of BusinessListBase

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


hanspret posted on Wednesday, November 10, 2010

Hi

I bought the MVVM video for silverlight. I designed a project exactly like the video. I'v setup a view to display a list of User exactly like the video showed. When I call the factory method ont the I get nothing back. The BusyAnimation keeps on runnig and the canvas on top of the form is still visible. The OnRefreshed nor the OnError method in the viewmodel get hit.

Below is code from the ViewModel. The Factory Method is GetAMSUserCollection.

 

 

 

 

 

 

public class UserViewModel : ViewModel<AMSUserCollection

>

{

 

 

 

public

UserViewModel()

{

 

 

 

Shell.Instance.ShowStatus(new Status { Text = "Loading list", IsBusy = true

});

BeginRefresh(

 

 

"GetAMSUserCollection"

);

My Architect is a 3 tier model so the factory method calls the dataportal on the server. I have stepped through the code and can see that the list is build up in the DataPortal_Fetch method. Here is the factory method code

public

 

 

static void GetAMSUserCollection(EventHandler<DataPortalResult<AMSUserCollection>> callback)

{

 

 

var dp = new DataPortal<AMSUserCollection>();

dp.CreateCompleted += callback;

dp.BeginFetch();

}

 

I even took all the code out in the factory method but still Iget no reaction in my UI. It is as if the WcfDataportal doesn't return anything.

Can anybody pleas give me an answer

RockfordLhotka replied on Wednesday, November 10, 2010

Override the OnError method in the viewmodel. If an error occurs during the async processing, this is where you'll be able to see it.

You might also override OnRefreshed, because this is where you'll first see a successful result.

hanspret replied on Wednesday, November 10, 2010

Hi Rocky

I did override the Onrefresh and OnError methods but execution is never getting to this two methods. I did test the same principals with an Editable BusinessBase object and everything worked 100%. But when I fetch a collection I don't get any response.

I debugged even to the class Csla.Server.Hosts.Silerlight.WcfPortal.Fetch, and I can see that the WCF is returning data without throwing an error but somehow it never reach my client

RockfordLhotka replied on Wednesday, November 10, 2010

Have you raised the limits on message size for WCF? Are you using compression?

Those steps are basically required for any real SL app, because the default WCF limits are so low as to be useless.

hanspret replied on Wednesday, November 10, 2010

Yes I did, both on the web.config and ServicesReferences.ClientConfig.

I did use Compression but took it out as I thought the compression might cause the problem.

Web.config:  

<?xml version="1.0"?>

<configuration>

<appSettings/>

<connectionStrings/>

<system.serviceModel>

<services>

 

<service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Silverlight.WcfPortal">

<endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal" bindingConfiguration="BasicHttpBinding_IWcfPortal">

<identity>

<dns value="localhost"/>

</identity>

</endpoint>

</service>

</services>

<behaviors>

<serviceBehaviors>

<behavior name="returnFaults">

<serviceDebug includeExceptionDetailInFaults="true"/>

</behavior>

<behavior name="WcfPortalBehavior">

<serviceMetadata httpGetEnabled="true"/>

<serviceDebug includeExceptionDetailInFaults="true"/>

</behavior>

</serviceBehaviors>

</behaviors>

<bindings>

<basicHttpBinding>

<binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="10000000" maxReceivedMessageSize="10000000" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">

<readerQuotas maxBytesPerRead="10000000" maxArrayLength="10000000" maxStringContentLength="10000000"/>

</binding>

</basicHttpBinding>

</bindings>

</system.serviceModel>

<system.web>

<!--

Set compilation debug="true" to insert debugging

symbols into the compiled page. Because this

affects performance, set this value to true only

during development.

-->

<compilation debug="true" targetFramework="4.0">

</compilation>

<!--

The <authentication> section enables configuration

of the security authentication mode used by

ASP.NET to identify an incoming user.

-->

<authentication mode="Windows"/>

<!--

The <customErrors> section enables configuration

of what to do if/when an unhandled error occurs

during the execution of a request. Specifically,

it enables developers to configure html error pages

to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

<error statusCode="403" redirect="NoAccess.htm" />

<error statusCode="404" redirect="FileNotFound.htm" />

</customErrors>

-->

<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>

</system.web>

<!--

The system.webServer section is required for running ASP.NET AJAX under Internet

Information Services 7.0. It is not necessary for previous version of IIS.

-->

</configuration>

 

 

ClientConfig

configuration>

<system.serviceModel>

<bindings>

<basicHttpBinding>

<binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="10000000" maxReceivedMessageSize="10000000" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">

 

</binding>

</basicHttpBinding>

</bindings>

<client>

<endpoint address="http://localhost:63719/WcfSlPortal.svc" binding="basicHttpBinding"

bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="WcfPortal.IWcfPortal"

name="BasicHttpBinding_IWcfPortal" />

</client>

</system.serviceModel>

</configuration>

RockfordLhotka replied on Wednesday, November 10, 2010

Then I really have no idea. If WCF isn't returning anything from the server then there's something wrong with WCF.

OnError will get any WCF exceptions on the client. Either the WCF call worked and you get OnRefreshed or it failed (or an exception flows back from the server) in which case you'll get OnError.

To get neither of them implies that the WCF request never completed at all and no async callback code ran on the client.

And even that is a little odd, since eventually you'd expect WCF to timeout on the client...

hanspret replied on Wednesday, November 10, 2010

Thanks for all your help. I actually feel to stupid to tell you what I did wrong.

 I sat 9 straight hours on this problem and just when tears start rolling of frustration I saw the problem (Sort of a typo in my Factory Method).

I am using Csla a while now with WPF and this is my first project with Silverlight. The Csla is for sure the best tool I ever encountered, keep up the good work.

RockfordLhotka replied on Wednesday, November 10, 2010

I am still puzzled as to why OnError didn't happen. What kind of typo did you have? I'd like to replicate the issue and find out why no exception came back to the client (this could be a bug in the data portal or ViewModelBase class).

hanspret replied on Thursday, November 11, 2010

In the fetch factory method I had:

public static void GetAMSUserCollection(EventHandler<DataPortalResult<AMSUserCollection>> callback)

{

var dp = new DataPortal<AMSUserCollection>();

dp.FetchCompleted += callback;

dp.BeginFetch();

}

public static void GetAMSUserCollection(EventHandler<DataPortalResult<AMSUserCollection>> callback)

{

var dp = new DataPortal<AMSUserCollection>();

dp.CreateCompleted += callback;

dp.BeginFetch();

}

Notice the difference? The second fetch factory method contains "dp.CreateCompleted += callback" while the first one is correct with dp.FetchCompleted.

The dp.CreateCompleted in the fetch factory method caused all the pain

Copyright (c) Marimer LLC