Published: 04 Apr 2008
By: Josip Zohil
Download Sample Code

This article explains how to set up a WCF client to download the data from the server in asynchronous (non blocking) mode, much faster than with VFP functions or oledb data adapters.

Introduction

In part one we talked about the problem and the WCF service as its solution. The WCF service accepts the request from the client, retrieves the data from the database and sends it to the client in various formats: string, DataSet, DataTable and strongly typed collections. We present the WCF client in this part of the article.

The WCF client

  • Create a new project named ComWfcVfpClient (See [4]). Rename the created class to ComWfcVfpClient.cs (Listing 6).

Listing 6: The WCF Client class

  • Create a new class ComEventArgs.cs (Listing 7).

Listing 7: The ComEventArgs class

  • In the class ComWfcVfpClient.cs (Listing 6) we define the delegate GridEventHandler and its event ReceivedData. We use it to pass the information to the subscribers (callers) of this class instance. We collect the information in the object eventArgs, generate the event and publish it with the command: this.ReceivedData(this, this.eventArgs);
  • Add a new Service reference to the WCF service (in our case net.tcp://192.168.123.63:8081/wcfvfpwstcp , see the key uri in app.config in the download). Name it WcfVfpWs. It generate the <client> and <binding> description in the app.config. Double click on the WcfVfpWs service reference in the Solution Explorer and select View in object browser. You see the service description used by the WCF client in conjunction with the app.config.
  • In the class ComWfcVfpClient.cs is the method WcfVfpWs.IService1Channel Proxy (Listing 6), which generate the client channel (the proxy) and add it few properties (about security, message size etc). When the client is done, the client needs to close the proxy transport channel [7].
  • In the class ComWfcVfpClient.cs we find similar methods as in the WCF service. We call the service methods in two ways: synchronous (blocking) and asynchronous which run the synchronous method on a new thread. For example the method:

calls the synchronous method StoreDataSet on a new thread (non blocking the VFP form). The above code is not a real callback to the server! It is only a local callback. The method StoreDataSetAsyn is delegating the task to the method StoreDataSet on a new thread and implicitly also the method (event) ReceivedData(this, eventArgs) is fired. It informs (call back) the callers (subscribers) of the results generated by the StoreDataSet. The callers receive the results in the form of two objects (sender - its type is object and eventArgs - of type ComEventArgs). The ComEventArgs type must be known to the caller! (We will present it in next parts).

About Josip Zohil

Josip Zohil, Koper, Slovenia, Josip.Zohil1@guest.arnes.si

This author has published 3 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category


Improve VFP data retrieval with WCF - Part Three
This article explains how to set up a WCF client to download the data from the server in asynchronou...
Improve VFP data retrieval with WCF - Part One
This article explains how to set up a WCF client to download the data from the server in asynchronou...
Transaction Propagation in WCF
In this article, I will explain how to configure transaction propagation in WCF.

You might also be interested in the following related blog posts


Announcing Microsoft Ajax Library (Preview 6) and the Microsoft Ajax Minifier read more
WPF Release History : Q2 2009 (version 2009.2.701) read more
Building a class browser with Microsoft Ajax 4.0 Preview 5 read more
Silverlight Release History : Q2 2009 (version 2009.2.701) read more
Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 7: ADO.NET Data Services Based Data Store read more
Introducing Versatile DataSources read more
Improving Dynamic Data with Peter's Data Entry Suite read more
Convert Web.UI ASP.NET Grid into a data entry spreadsheet read more
Web.UI 2008.2 Grid News: Grouping read more
Web.UI 2008.2 Grid News: Grouping read more
Top
 
 
 

Please login to rate or to leave a comment.

Product Spotlight