Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ToString() method on objects returned from a webservice (Compact framework) [modified]

ToString() method on objects returned from a webservice (Compact framework) [modified]

Scheduled Pinned Locked Moved C#
helpquestiondebuggingtutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    c0ax_lx
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • C c0ax_lx

      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

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      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.

      C 1 Reply Last reply
      0
      • S SeMartens

        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.

        C Offline
        C Offline
        c0ax_lx
        wrote on last edited by
        #3

        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!

        S 1 Reply Last reply
        0
        • C c0ax_lx

          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!

          S Offline
          S Offline
          SeMartens
          wrote on last edited by
          #4

          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.

          C 1 Reply Last reply
          0
          • S SeMartens

            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.

            C Offline
            C Offline
            c0ax_lx
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups