oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

A Quick Tour of .NET Web Services
Pages: 1, 2

Windows Forms Client

Here is a Windows Forms client that you can link against the ADOWebSvc.cs proxy that was generated by wsdl.exe. Save this as WFClient.cs, and compile it with:

  csc /t:library ADOWebSvc.cs
  csc WFClient.cs /r:ADOWebSvc.dll

Example 5. Source code for WFClient.cs

// ADO.NET Web Service Client
// based on an example from Chapter 6 of
// .NET Framework Essentials
//    by Thuan Thai and Hoang Q. Lam
//    (2002, O'Reilly & Associates)

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;

class WinFormClient
  static void Main() 
    // Create the proxy.
    ADOWebSvc proxy = new ADOWebSvc();

    // Get the data set.
    DataSet ds = proxy.GetAuthors();

    // Associate a data grid with 
    // the DataSet.
    DataGrid dg = new DataGrid();
    dg.Size = new Size(590, 370);
    dg.DataSource = 

    // Create a form and add the 
    // DataGrid to it.
    Form f = new Form();
    f.Text = "DataSet/DataGrid";
    f.Size = new Size(600, 400);

    // Start the application.

Figure 2 shows this application in action.

Figure 2. Browsing the a .NET data set from a Windows Forms client.

Visual FoxPro Client

Visual FoxPro wasn't as easy, but you can pull the XML-serialized data set into a text file and start mercilessly chopping away at it until something feeds into Visual FoxPro's XMLTOCURSOR() function.

When I get the data set back from the .NET Web service, it looks roughly like this:

<DataSet> ... 
  <xs:schema> ... </xs:schema>
  <diffgr:diffgram> ...
    <NewDataSet> ... </NewDataSet>

You want the following <NewDataSet> element and everything it contains. The only problem is that some of the elements in it contain references to outer namespaces, as in:

<Authors diffgr:id="Authors2" msdata:rowOrder="1">

By stripping these out, you end up with something to feed into XMLTOCURSOR() and browse (see Figure 3).

Figure 3. Browsing the a .NET data set.

Example 6. Visual FoxPro Client

* IntelliSense-generated code appears here *

LOCAL dotnetDS as String
LOCAL vfpDS as String
LOCAL dsrows as String

* Get the .NET Data set. It looks like:
*   <DataSet> ... 
*     <xs:schema> ... </xs:schema>
*     <diffgr:diffgram> ...
*       <NewDataSet> ... </NewDataSet>
*     </diffgr:diffgram>
*   </DataSet>
* We want the NewDataSet, since it contains the rows.
dotnetDS = oWS.GetAuthors
dsRows = dotnetDS.item[1].firstChild.xml

* strip out references to XML namespaces that are
* no longer part of this XML document.
vfpDS = STRTRAN(STRTRAN(dsRows, "diffgr:", ""), "msdata:", "")

* Perform the conversion.

* See how it looks!

Not quite XSLT, but it gets the job done quickly and easily. For documentation on registering Web services with Visual FoxPro and using IntelliSense to insert consumer code, see this MSDN article.

Brian Jepson is an O'Reilly editor, programmer, and co-author of Mac OS X Panther for Unix Geeks and Learning Unix for Mac OS X Panther. He's also a volunteer system administrator and all-around geek for AS220, a non-profit arts center in Providence, Rhode Island. AS220 gives Rhode Island artists uncensored and unjuried forums for their work. These forums include galleries, performance space, and publications. Brian sees to it that technology, especially free software, supports that mission. You can follow Brian's blog here.

Return to the .NET DevCenter.