views:

8

answers:

1

I got a class like this which gets returned from an ASP webservice:

class Data {

public int A { get; set; }

public int B { get; set; }

public int Sum { get { return A + B; } }

}

When I try to consume the webservice on the client side using Silverlight I only get the properties A and B but I also need Sum. I know I can't return any logic from a webservice, so the expected behavior was it will return the the Sum as a fixed/precalculated property in the client which is what I need.

Any ideas except for redesigning my class?

Thanks ...

A: 

You need to specify which version of C#/.NET you are using.

In previous versions, you could only serialize properties that had both get AND set defined for them.

It looks like that's what is giving you your trouble. You can try adding the following code to see if that is what's stopping you:

public int Sum 
{
    get
    {
        return A+B;
    }
    set
    {
        throw new NotImplementedException("Can't serialize this direction.");
    }
}
Justin Niessner
I'm compiling the webservice targeting .net 3.5 and Silverlight targeting Silverlight 4 ...
badra
WCF Service or ASMX Web Service?
Justin Niessner
asmx webservice
badra
Thanks, adding the setter seems to work ...
badra