开发者

ASP webservice serialization of properties

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 ex开发者_如何学Ccept for redesigning my class?

Thanks ...


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.");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜