ToString() method on objects returned from a webservice (Compact framework) [modified]
-
Hi. I'm having a problem and cannot find the solution. trust me, i've read lots on msdn and google'd, in the wrong places obviously but i hope someone here can help me. I'm porting an application to compact framework 3 and to reduce client side load i created a webservice for the BL (also, else i would have to copy all code and compile to CF since i cant use "regular" dll's in CF) this webservice exposes some custom classes and a couple of methods. a simple example would be (in webservice) public enum ToStringType { FirstName, LastName } public class person { public string firstname {get;set;} public string lastname {get;set;} public ToStringType stringtype {get;set;} public person(){ stringtype = ToStringType.FirstName ; } public override ToString(){ public override string ToString() { string tostr = string.Empty; switch (stringtype ) { case ToStringType.FirstName : tostr = FirstName; break; case ToStringType.LastName: tostr = LastName; break; } return tostr; } and the ws has a method returning person[] on the client. when i run the method and get a list of persons first of all: myperson.ToString() returns the object class name. not first/last-name so i add a method: tostr (){ ... } with the logic in tostring(), this works. returns firstname. but if i (on the client) myperson.stringtype =ToStringType.LastName; and debug the application, i see that myperson.stringtype IS ToStringType.LastName but the method returns firstname. i would really get the tostring to work since i'm adding the person[] to a combobox and i prefer not to use datasource/bindings. (tried those to. same problem, Displaymember has no effect) how come this split personality disorder in my classes, and why does ToString return the class name instead of my overloaded ToString method? I hope someone can help me regards Tomas
There is no spoon
modified on Tuesday, June 30, 2009 10:54 AM
-
Hi. I'm having a problem and cannot find the solution. trust me, i've read lots on msdn and google'd, in the wrong places obviously but i hope someone here can help me. I'm porting an application to compact framework 3 and to reduce client side load i created a webservice for the BL (also, else i would have to copy all code and compile to CF since i cant use "regular" dll's in CF) this webservice exposes some custom classes and a couple of methods. a simple example would be (in webservice) public enum ToStringType { FirstName, LastName } public class person { public string firstname {get;set;} public string lastname {get;set;} public ToStringType stringtype {get;set;} public person(){ stringtype = ToStringType.FirstName ; } public override ToString(){ public override string ToString() { string tostr = string.Empty; switch (stringtype ) { case ToStringType.FirstName : tostr = FirstName; break; case ToStringType.LastName: tostr = LastName; break; } return tostr; } and the ws has a method returning person[] on the client. when i run the method and get a list of persons first of all: myperson.ToString() returns the object class name. not first/last-name so i add a method: tostr (){ ... } with the logic in tostring(), this works. returns firstname. but if i (on the client) myperson.stringtype =ToStringType.LastName; and debug the application, i see that myperson.stringtype IS ToStringType.LastName but the method returns firstname. i would really get the tostring to work since i'm adding the person[] to a combobox and i prefer not to use datasource/bindings. (tried those to. same problem, Displaymember has no effect) how come this split personality disorder in my classes, and why does ToString return the class name instead of my overloaded ToString method? I hope someone can help me regards Tomas
There is no spoon
modified on Tuesday, June 30, 2009 10:54 AM
Why didn't you make lastName public like firstName?
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Why didn't you make lastName public like firstName?
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Edited, Thanks for noticing! allthough this was just an example and not the actual code, else the post would have been very very long
If it' stuck, DO NOT pull harder!
Maybe the StringType is not serialized correctly. I think you have to think about, how to serialise this type...
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Maybe the StringType is not serialized correctly. I think you have to think about, how to serialise this type...
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
I tried changing StringType to int. did nothing. This confuses me a little. The properties of the object can be modified and keeps their state on the client. but all changes are lost on the server. since it is stateless one would think that the "original" values also would be lost, and why isnt the client object values passed to the server for method invocation. thank god for Apress Books and vacation coming up :) Anyway, i solved this by having a local class with the same properties and my custom ToString.
If it' stuck, DO NOT pull harder!