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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. Webservices and Custom Type Objects

Webservices and Custom Type Objects

Scheduled Pinned Locked Moved Web Development
sysadminhelpquestion
4 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.
  • J Offline
    J Offline
    JoostV
    wrote on last edited by
    #1

    Hi all, I'm kind of a newby in webservices so I think this will be a simple question for you all. I want to create an object on de webservice side (server) and return it to the application (client). The object on the client side must have the methods of the original object. The code on the client side: [webmethod] public car createCar (string licenceplate) { car car = new car(licencePlate); return car; } method in object class file (car.cs) public string getLicencePlate { return this.licencePlate; } on the client side i want to ask the object its licenceplate. So: car.getLicencePlate(); But i can't see the methods. I only get the public attributes (and i don't want those) Does anyone have a clear sample of returning Custom Type objects with WebServices or maybe give me a lesson in Serializable. Ow.. I forgot... the client side is reacting asyn. I hope someone can help me. Kind regards, Joost Voskuil The Netherlands.

    H 1 Reply Last reply
    0
    • J JoostV

      Hi all, I'm kind of a newby in webservices so I think this will be a simple question for you all. I want to create an object on de webservice side (server) and return it to the application (client). The object on the client side must have the methods of the original object. The code on the client side: [webmethod] public car createCar (string licenceplate) { car car = new car(licencePlate); return car; } method in object class file (car.cs) public string getLicencePlate { return this.licencePlate; } on the client side i want to ask the object its licenceplate. So: car.getLicencePlate(); But i can't see the methods. I only get the public attributes (and i don't want those) Does anyone have a clear sample of returning Custom Type objects with WebServices or maybe give me a lesson in Serializable. Ow.. I forgot... the client side is reacting asyn. I hope someone can help me. Kind regards, Joost Voskuil The Netherlands.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      First, the method attributed with WebMethodAttribute must be on the server-side. You use the WSDL (contract) for the WebService to create a proxy object (i.e., an object that the client uses to proxy calls to the WebService). As far as serialization goes, there is an example in your .NET Framework SDK. See <SDK>v1.0\Samples\Technologies\Serialization. You should also take a look at the System.Xml.Serialization. Many of the classes and methods in that namespace have example source code. It's just another way to control serialization that's designed more for XML. Just attributed classes and properties with various XML serialization attributes and have a public default constructor (a public constructor with no parameters). Ultimately, serialization will get you farther (like with remoting), but I thought I'd mention XML serialization as an alternative when using WebServices (also handy to persist application settings and documents that you want other applications to be able to read easily). Whichever way, just create an class that is attributed with SerializableAttribute (and optionally implements ISerializable, or that uses the attributes in System.Xml.Serialization. Pass that type as a parameter (or as a return value) in your WebService method and that's really all you need to do.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      J 1 Reply Last reply
      0
      • H Heath Stewart

        First, the method attributed with WebMethodAttribute must be on the server-side. You use the WSDL (contract) for the WebService to create a proxy object (i.e., an object that the client uses to proxy calls to the WebService). As far as serialization goes, there is an example in your .NET Framework SDK. See <SDK>v1.0\Samples\Technologies\Serialization. You should also take a look at the System.Xml.Serialization. Many of the classes and methods in that namespace have example source code. It's just another way to control serialization that's designed more for XML. Just attributed classes and properties with various XML serialization attributes and have a public default constructor (a public constructor with no parameters). Ultimately, serialization will get you farther (like with remoting), but I thought I'd mention XML serialization as an alternative when using WebServices (also handy to persist application settings and documents that you want other applications to be able to read easily). Whichever way, just create an class that is attributed with SerializableAttribute (and optionally implements ISerializable, or that uses the attributes in System.Xml.Serialization. Pass that type as a parameter (or as a return value) in your WebService method and that's really all you need to do.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        J Offline
        J Offline
        JoostV
        wrote on last edited by
        #3

        Thanx Heath, What you mention helped me allot. Still figuring out the stuff, though. I have the system working now, but I’m certainly that it is al real quick and dirty solution. Do you have a clear example how you work? Thanx in advanced

        H 1 Reply Last reply
        0
        • J JoostV

          Thanx Heath, What you mention helped me allot. Still figuring out the stuff, though. I have the system working now, but I’m certainly that it is al real quick and dirty solution. Do you have a clear example how you work? Thanx in advanced

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          I don't, no, but there's plenty of examples here on CP and that you can find via google. Really, though, it's not difficult - just create an object that is serializable (or uses the attributes in the System.Xml.Serialization namespace and use that as your param or return type.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          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