Modifying the Proxy Class to Return Fat Objects

By default Web Services return dehydrated classes. I call these classes dehydrated because when you return a complex type from a Web Service, you get a fields-only class. However, if you want a reconstituted object from a Web Service, you can get one with a bit of chicanery.

Assume for a moment that you are building Web Services to bridge applications internally or for select customers. These customers will have your library. If this is the case, you can modify the WSDL-generated proxy class by removing the generated proxy class and referencing your .dll assembly that contains the actual object. Voil ! You have created reconstituted, or fat, objects.

If you like your milk whole instead of powdered and real objects instead of flat versions of those objects, follow these steps.

  1. Generate the proxy class for a Web Service that returns a complex type.

  2. Edit the file containing the proxy code by removing the flat, fields-only proxy class that represents the complex type.

  3. Add a reference to the assembly that contains the actual complex type code and definition of your Web Service client.

  4. Add an Imports statement to the proxy class indicating the namespace of the real class.

When you are finished, your client application will think it is getting an actual object back from the Web Service.

As an alternative, suppose you have a Web Service that returns a complex type, but you do not have the original assemblies defining the real types instead of the generated types. Never fearyou can roll your own! That's right. Create a new assembly that has public properties with getters and setters that match the fields in the generated proxy class. Add the code you are interested in associating with the type returned from the Web Service, then modify the proxy file to refer to the custom type. Again, you have real objects instead of dehydrated ones.

Clearly, you don't have to do any of these things. You can take whatever the WSDL tool and the Web Service gives, but that wouldn't be very advanced. We are the masters of our domain, and the code bends to our will.

Visual Basic. NET Power Coding
Visual Basic(R) .NET Power Coding
ISBN: 0672324075
EAN: 2147483647
Year: 2005
Pages: 215
Authors: Paul Kimmel © 2008-2017.
If you may any questions please contact us: