Data-Binding to Web Service Proxies

As I was preparing to post this code, I ran across Brad Adams very timely post:
   Nikhil fires up the age old debate again…Data-binding to public fields... yes or no?

My problem, more specifically, is data-binding to web service proxies.  The client proxies generated by .NET 1.0 & 1.1 represent the data elements returned by a web service as fields.  While this works fine for retreiving data, it does absolutely no good when trying to bind the data to a grid.

While .NET affords some extensions for web service client code generation, the data classes are generated by the serialization framework and it does not support customization AFAIK.  So what can be done?  Wait for .NET 2.0?  Being the impatient programmer, I decided to go down a different path. 

I've been following the Mono project for a while, and I knew they had an open-source port of .NET's WSDL.EXE tool.  I downloaded the source code and patched together a new WSDL tool that runs under .NET 1.0, 1.1, or Mono.  It was definitely a quest!  I interwove the System.Web.Services & System.Serialization classes from the Mono library with the base runtime classes.  This allowed me to tweak the code generator to produce the desired result while running on either MS.NET or Mono. Thanks to the Mono Team for making this code available... definitely a good reason for open-source!

The new tool has an additional flag (-eap or -elementasproperty) to generate properties instead of fields.

Here's how to run the tool:

   D:\wsdl>wsdl -eap 

   Mono Web Services Description Language Utility
   Modified by Brian Ritchie to support extended proxy generation under
   Mono or MS.NET runtimes.

   Writing file 'States & Provinces.cs' 

The following is an example of the generated code: (portions removed to save space)

class RegionItem {    
      private string _label;    
      private string _data;

      public virtual string label
       get {
            return this._label;
         set {
            this._label = value;
      public virtual string data 
         get {
            return this._data;
         set {
            this._data = value;

As opposed to the .NET 1.0/1.1 generated code:

   public class RegionItem
      public string label;
      public string data;

I've created a sample WinForms application to demonstrate data-binding against the generated proxy.  The WSDL tool source & binary can be downloaded here.

Note: The project & compiled code are VS.NET 2003/.NET 1.1.  However, it can be compiled under 1.0 or Mono.



Comments have been disabled for this content.