The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

property in proxy stub doesn't get serialized

Last post 06-30-2008, 10:55 AM by TrevorW. 5 replies.
Sort Posts: Previous Next
  •  06-28-2008, 1:56 PM 10052

    property in proxy stub doesn't get serialized

    I'm trying to pass a calculated property from my entity through to the client side proxy. To accomplish this, I've added a public property to the server side proxy, and the getter simply returns entity.MyProperty. I've verified that entity.Myproperty is indeed returning what I expect, but when I serialize the server side proxy, it doesn't include my property in the XML, so the client side interprets it as the default for the type instead of the actual calculated value.

    I've essentially duplicated the template code for server side proxy properties, except I don't call IncludeColumn. I'm really stumped. Any help you can provide would be greatly appreciated.

    Here's my server side proxy code:

     

    Code:
            [DataMember(Order = 0)]
            public decimal TotalPremium
            {
                get
                {
                    return entity.TotalPremium;
                }
            }
     
  •  06-28-2008, 11:08 PM 10055 in reply to 10052

    Re: property in proxy stub doesn't get serialized

    Am I missing something? How can the value be serialized without a setter or by overriding the serialization to save a private variable value? In other words, where is the value saved when serialized?

    Alternatively, what values are used to determine the TotalPremium? You say it is calulated, but the example shows no calculation.

    For example, If I have a value for SalePrice, I might "calculate" the TotalPremium value like this:

            [DataMember(Order = 12)]
            public decimal TotalPremium
            {
                get
                {
                    return entity.SalePrice * .12;
                }
            }

    Further, you have the DataMember(Order=) value at 0 (zero). WCF uses that number/value to determine serialization/deserialization order. In my example, that value cannot be zero because the SalePrice value must be serialized/deserialized first or the calculation will either fail or produce the wrong value. My example sets the order at 12; thus, the SalePrice column must have a value lower than 12 or the result is wrong.

     

     

     

  •  06-29-2008, 7:08 AM 10061 in reply to 10055

    Re: property in proxy stub doesn't get serialized

    It's obvious I'm missing something here, not you. ;) I am rather new to working with seralization and WCF.

    I left the calculation out for brevity. TotalPremium is a read only property on the entity, and is where the calculation happens. As far as the proxy class is concerned, it is the same as another data column. And since the proxy is serialized after the entity exists, I didn't think the order mattered. Am I wrong?

    I looked at how the generated proxy classes work, and they do essentially the same thing I am doing. They don't seem to have a private variable. They have a getter and setter that work directly on the entity value. But since my extra calculated property on the entity doesn't have a setter, as it doesn't make sense, I left that out.

    As far as where the data is saved, I assumed the XML when serialized. The client side proxy class has a property with a backing store to save it, but I looked at the generated XML from the server side proxy and this property is not there, so I don't think the problem lies on that side. It has to be that I'm doing something wrong on the server side.

     


     

     

  •  06-29-2008, 8:02 AM 10062 in reply to 10061

    Re: property in proxy stub doesn't get serialized

    Also, this note from the WCF docs leads me to believe I'm at least sort-of on the right track.

    During serialization, property-get code is called for property data members to get the value of the properties to be serialized. 

  •  06-29-2008, 8:28 AM 10063 in reply to 10062

    Re: property in proxy stub doesn't get serialized

    Okay, I figured it out, though I have no idea why this fixed it.

    All I did is add a completely empty setter:

     

    Code:
            [DataMember(Order=0)]
    public decimal TotalPremium
    {
    get
    {
    return entity.TotalPremium;
    }
    set
    {

    }
    }
     
  •  06-30-2008, 10:55 AM 10067 in reply to 10063

    Re: property in proxy stub doesn't get serialized

    Each serializer has its own rules on how it selects properties to serialize/deserialize. Essentially, some (most) inspect the properties and look for a getter and setter, if the property has both, its flaged to store/restore; if it does not, it ignores it. Your solution poses some risks using different serializers and may not work will all of them. Also, for some serializers, all you would need to do is mark the property, or an associated underlying private field, with the Serialazable attribute. For others, it may be best to inherit from the ISerializable interface (I believe) and manually setup how the objects are serialized/deserialized.
View as RSS news feed in XML