Click here to Skip to main content
13,447,245 members (37,357 online)
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 13 Oct 2003

Pay-Per-Click webService and client implementation

, 13 Oct 2003
Rate this:
Please Sign up or sign in to vote.
Introduction into the world of pay-per-click webservices with sample web service and client application


This articles demonstrates a sample client application and a web service that consumes data feed provided by to their affiliate partners. You'll be able to learn about distribution and logging practices in the PPC world and to get access to your very own data feed with direct access to real time data.

Using the code

FindWhat PPC (Pay-Per-Click) webservice and client implementation

PPC or (Pay-Per-Click) providers have been around for sometime now and they are recognized as one of the hottest segments in online marketing business. PPC engines were one of the first companies that have recognized opportunities presented with development of XML Web Services. They use XML and Web Services extensively to provide distribution of search results among their partners.

PPC Engine Definition: A search engine that allows webmasters to purchase their positions within the search results based on the amount of money they are willing to pay for each click thru their site's listing receives.

Developers can utilize wide range of tools and technologies to build applications that can interact with data providers and develop various client applications that consume web services maintained by PPC engines.

After reading this article you’ll be able to do the following:

  • to download your very own web client application that queries databse
  • to learn about distribution and logging practices in the PPC world
  • to get access to your very own data feed

Our company ( is one of the partners with and we had to go through a process of consuming XML data feeds ourselves. This article is a starting point for anyone interested to peek under the hood of PPC world.

Let’s start from description of our architecture that we are going to utilize.

One of the key requirements that we had to comply with was a license agreement that allowed us to distribute PPC links through a single gateway URL on our servers. We have several other websites (,, where we would like to publish retrieved search results but for tracking purposes we have licensed single URL to simplify administration and maintenance. Naturally, for our own internal distribution of searches, Web Service implementation was the obvious choice. We have created a web service that we host ourselves and provide centralized distribution of search results among all our network websites.

Our main service is freely available at:

We have decided to build our own web service that will help us with logging and querying database in real time and delivering results consistently across our range of websites that will consume this data. Our web service must be able to log searches and IP addresses into database for future analyzes and be very responsive under heavy load.

Our client application will be a simple ASP.NET form that allows us to post queries to our web service and consume returned datasets.

With this in mind let’s start with simple web service.

GetDataSet( )

Our main Web Service method will require 4 input variables. Our web service consumes raw XML data from cluster and generates DataSet that we use in our client applications. We have decided to use DataSets as our primary way of exchanging data to have capability to develop lightweight client applications that could directly bind to already structured and properly formatted data.

Description of parameters is quoted from documentation.

public DataSet GetDataSet(string Query, 
  string IPAddress, 
  int BaseRecord, 
  int RecordCount)

Query - An HTML encoded text string representing what the user is searching for. It is important that the text string is encoded properly according to RFC1738. Specifically, non-alphanumeric characters must be encoded as per this excerpt from RFC1738:

“In addition, octets may be encoded by a character triplet consisting of the character "%" followed by the two hexadecimal digits (from "0123456789ABCDEF") which forming the hexadecimal value of the octet. (The characters "abcdef" may also be used in hexadecimal encodings.)  Octets must be encoded if they have no corresponding graphic character within the US-ASCII coded character set, if the use of the corresponding character is unsafe, or if the corresponding character is reserved for some other interpretation within the particular URL scheme.”

A very common encoded octet is that of the space character in the US-ASCII set. A space is ASCII value 32 (decimal), 20 (hexadecimal). Therefore, to encode “free email” into the request URL to our servers, you would need to replace the space with “%20”, resulting in “free%20email” as your final encoded string.

  • IPAddress – A text string representing the IP address of the user who initiated the search. THIS PARAMETER IS NOT THE IP ADDRESS OF YOUR SERVERS.  This is extremely important to include to receive full credit for all searches and click-throughs.
  • BaseRecord - An integer value representing the first record to retrieve from FindWhat data cluster.  For the initial request for any result set, this is always 0.
  • RecordCount - An integer value representing the document count, or number of documents to retrieve from FindWhat data cluster. The default is 25

Let’s take a look at what is going on inside the Web service. (Note: We can’t disclose complete source code due to restrictions posted by our license but we do provide complete code for the client application.)

We log all searches and IP addresses into MS SQL Server 2000 database for future analyzes by our marketing people by using Business component layer.

// Log Search Query and IPAddress into the database

// Load Xml data retrieved from cluster into DataSet

DataSet ds = new DataSet();
XmlTextReader r = new XmlTextReader(

Visual Studio Class View


/// Builds well formatted URL based on requested parameters.
/// Method signature: 
/// GetUrl(string Query, 
///    string IPAddress, 
///    int BaseRecord, 
//    int RecordCount)

private string GetUrl(string Query, 
          string IPAddress, 
          int BaseRecord, 
          int RecordCount)

This methods is used to build properly formatted URI string that we use to access remote data source. This URI includes assigned partner id and other information necessary to get access to search cluster that services all web based requests.


/// Public method returns default DataSet.
/// Method signature:
/// GetDataSetDefault()
/// Default dataset is used as a placeholder for cases 
//  when  search results return "0" 
/// records or when exception occurs 
/// during execution of the request.
/// Default DataTable is constructed to provide links 
/// to our own websites when search query returns 
/// "0"records or in case of a default search. 

public DataSet GetDataSetDefault()

GetDataSetDefault() and GetDataSet()  are both exposed as public web methods to provide flexible way for client applications to access search results.

PPC Client Application

Now that we have an idea how simple the web service is we need to implement a simple client application. Our Web Service conveniently returns to us already formatted dataset that we can use to directly bind to ASP.NET Datagrid control.

You can implement variety of applications based on the results returned from the web service. Keyword monitoring, positioning and keyword market assessment are just a few examples of applications that you can build. You can use this information to make smarter decisions about what keywords are in demand and look for niche keywords that cost significantly less but could provide more targeted traffic to your website.

Main method is listed below to give you an example on how to call web service from your source code.

private void SearchButton_Click(object sender, System.EventArgs e)
  // Retrieve FindWhat result
  com.automob.wsdemo.PPC ppc = new com.automob.wsdemo.PPC();
  // Databind restrieved recordset
  SearchResults.DataSource = ppc.GetDataSet(Request.Form["Query"]

If you download the sample client application and run it on your local host you’ll be able to see the following results from your browser.


In Pay-per-Click world keyword prices and URL positions change daily if not hourly. It would be almost impossible to maintain quality keywords on your list without researching keyword value and conversion rates for each individual keyword. Access to web services that provide you with raw data can give you information and real time statistic ultimately allowing you to better convert your generated clicks into qualified leads and your own customers.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Yuriy Maksymenko
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Questionis the webservice still online Pin
eben23625-Nov-06 21:59
membereben23625-Nov-06 21:59 
GeneralHola amigos Pin
Anonymous21-Jan-05 9:11
sussAnonymous21-Jan-05 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180318.3 | Last Updated 14 Oct 2003
Article Copyright 2003 by Yuriy Maksymenko
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid