Click here to Skip to main content
13,088,846 members (69,603 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 6 Jun 2013

A Batch process using RESTful WCF Service

, 6 Jun 2013
Rate this:
Please Sign up or sign in to vote.
This tip contains a solution for a Batch process which invokes a RESTful WCF Service.

Sample Image


A Batch program takes a set of data files as input, processes the data, and produces a set of output data files. The input data is usually a collection of .txt or .xml, a typical batch program monitors a directory, starts processing on ‘arrival’ of the files, and generates the output or rejected files. There are situations when the Batch process has to make web service calls to third party applications for checking the incoming input files. Consider a telecommunication provider of local, national, or international calls. A provider like AT&T often uses the equipment, wiring, and transmission of other carriers like Verizon, Sprint, and SBC to provide service to the customer. When a new number is provisioned, the provider has to check with other carriers for preparing and equipping a network to allow it to provide (new) services to its users. This process requires invoking web service calls.


In this article, the batch program is processing the area code. The name of the input file indicates an area code, i.e., 101.txt represents the area code 101. The application makes a web service call if this area code is valid for the network. If it is not it rejects the file with a rejection message, “Not served by partner carrier”. The batch process uses the FileSystemWatcher object. The main console batch process spawns a new thread and the FileSystemWatcher monitors the source folder for input files.

Using the code

If there are new files in the folder, it starts processing. Else it waits for the file creation event. If there are incoming flies, the event is fired and the batch process is signaled that it can start processing again. The batched query requests are sent to the WCF service which is translated into REST-based operations. The web method returns a Response object which represents responses to individual queries in the batch. Based on the response, the files are either rejected or are processed.

string[] lstr_arryFilesInDirectory = Directory.GetFiles(_strSourceDir);
// Begin watching.
if (lstr_arryFilesInDirectory.Length > 0)
    watcher.EnableRaisingEvents = false;
    watcher.EnableRaisingEvents = true;

The article download contains two components: BatchProcess and WcfValidationService. You will need to create the Source, Target, and Reject folder (the location is hardcoded in the config file). There are also sample input files which are available in the source folder of the BatchProcess project. To run the application, start the WcfValidationService and then the console based BatchProcess. After that copy the input .txt files to the source folder. A successful operation will move these .txt files to the Target and Reject folders, respectively.

Points of Interest

The application uses LINQ and the Repository pattern in the web service.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
United States United States
I am passionate on coding and application development specially in the .NET C# windows and web platform.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 6 Jun 2013
Article Copyright 2013 by Ankurkumarbora
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid