Return List<double> in Silverlight WCFPortal

Return List<double> in Silverlight WCFPortal

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


Gort posted on Tuesday, September 13, 2011

I am developing a SL application and need to pass a List<short> to the factory method and   return a List<double>.  How would I go about doing this?

Currently, I get an error:

Type 'System.Collections.Generic.List`1[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' with data contract name 'ArrayOfdouble:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

I know how I would go about this if I was using my own WCF service, but am not sure how to do it using the Csla.Server.Hosts.Silverlight.WcfPortal.

Tks.

RockfordLhotka replied on Wednesday, September 14, 2011

This has been discussed a few times.

  1. The data portal uses the MobileFormatter.
  2. The MobileFormatter requires all types implement IMobileObject.
  3. That is hard, so you should try to use the pre-build types we provide - like Csla.Core.MobileList

 

Gort replied on Wednesday, September 14, 2011

Thanks for the response, Rocky.

I got this to work for my return list of doubles, but can't seem to get it to work for my criteria class where I need to pass in a list of short values.  I get the same error when attempting to pass a MobileList<Int16> within the criteria class.  Should this work in that case too?

Tks

Gort replied on Wednesday, September 21, 2011

Does anyone have any thoughts or ideas as to why this is not working?

Tks much!

RockfordLhotka replied on Wednesday, September 21, 2011

The property in your criteria class needs to be a managed property for CSLA to automatically treat it like a child object. Is your property a managed property?

Gort replied on Thursday, September 22, 2011

Here is how my property looks in my critieria class:

public MobileList<Int16> VariableIds
{
  get { return GetValue<MobileList<Int16>>("VariableIds"); }
  set { _bag["VariableIds"] = value; }
}

The error I get is:

Type 'Csla.Core.MobileList`1[[System.Int16, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' with data contract name 'ArrayOfshort:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

JonnyBee replied on Thursday, September 22, 2011

Your criteria property should look like this:

    public static PropertyInfo<MobileList<Int16>> VariableIdsProperty = RegisterProperty<MobileList<Int16>>(c => c.VariableIds);
    public MobileList<Int16> VariableIds
    {
      get { return GetProperty(VariableIdsProperty ); }
      private set { LoadProperty(VariableIdsProperty , value); }
    }

Your property read the managed property value and set a totally different property in _bag.

Gort replied on Thursday, September 22, 2011

Ok.  I tried this but it seems that 'GetProperty(...)' is not a method within the 'CriteriaBase' class.  I can't seem to find it. 

JonnyBee replied on Thursday, September 22, 2011

Which version of Csla are you using?

Gort replied on Thursday, September 22, 2011

v4.0.30319

RockfordLhotka replied on Thursday, September 22, 2011

There should be ReadProperty and LoadProperty methods. There wouldn't be GetProperty or SetProperty, because CriteriaBase has no support for business or authorization rules.

Gort replied on Thursday, September 22, 2011

Yep, that did it.

Rocky and JonnyBee, thanks so much for your help!

Copyright (c) Marimer LLC