Data Access Worldwide Knowledge Base

Article ID 2315
Article Title HOWTO: Log Calls to Web Service Functions and Generate Statistics
Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=2315
KBase Category WEB APPLICATIONS
Date Created 05/23/2007
Last Edit Date 04/23/2008


Article Text
This article provides information on two alternatives on how to log calls made to web service functions and how to generate statistics on the service usage.

The first one is a local solution, i.e. you modify the workspace containing the web services and all access will be logged in your workspace. The second one uses web service calls to a logging service hosted by Data Access Europe. All access will be saved to the files at Data Access Europe.

I. Modifying your workspace
----------------------------------------
If you want to check the usage of your web service and its published functions, you can add that functionality by incorporating the attached files into your workspace.

Those files will save the number of calls made to the functions you decide to control (along with dates) and will also provide the basis for usage statistics.

The following is the list of files included in the attached ZIP:
\AppHtml
AdminPage.htm (*)
History.asp
ResetStatistics.asp
Statistics.asp

(*) From the AdminPage you will be able to reset general (system) counters and run the statistics and history reports.

\AppSrc
History.wo
ResetStatistics.wo
ServiceCallLogging.pkg
Statistics.wo

\Data
filelist.cfg
funchour.dat
funchour.hdr
funchour.k1
funchour.tag
funcstat.dat
funcstat.hdr
funcstat.k1
funcstat.k2
funcstat.tag
history.dat
history.hdr
history.k1
history.K2
history.K3
history.K4
history.K5
history.tag
system.dat
system.hdr
system.tag

\DDSrc
FuncHour.DD
FuncHour.DEF
FuncHour.FD
FuncStat.DD
FuncStat.DEF
FuncStat.FD
History.DD
History.DEF
History.FD
system.DD
system.DEF
system.FD

In order to log the calls to your web service functions using those files, you will need to:

1. Make a backup copy of your workspace

2. Unzip the attached ZIP into your workspace (it includes a filelist; you might need to add the data files to your current filelist)

3. Add the following to your oWebApp object
Use ServiceCallLogging.pkg

Send SaveDateServiceStartedToRun

4. Add the following web objects to your WebApp project
oHistory (History.wo)
oResetStatistics (ResetStatistics.wo)
oStatistics (Statistics.wo)

5. Add the following to the end of the function you would like to record statistics for
Send UpdateInvoked <function_name>

6. Recompile your WebApp -- all the calls to your functions will be logged. You will be able to use the statistics page to analyze the usage of each one of your functions.

II- Using Data Access Europe Web Service
--------------------------------------------------------
If you do not want to mix statistics files with your workspace's files, you could also create a call to a central logging site created by Data Access Europe.

To get that working you will need to:
1. Create a login account
2. Activate your account
3. Add services to your account
4. Log statistics for your functions

1. Create a login account
To do that you need to create a login account. Use the option Accounts Maintenance | CreateAccount from the AdminPage at http://webservices.daehosting.com/usagelog/adminpage.htm. You should provide an account (LoginID), a password and a flag (True or False -- to indicate whether the statistics should be public or only available to you).

After executing CreateAccount, it will display your account ID. SAVE THAT NUMBER as you will need it for adding services and use the logging function.

2. Activate your account
Also, after adding an account, you will need to send an e-mail to support@dataaccess.nl asking to have your account approved. This is done to avoid that bots can create accounts and that we end up with crap.

3. Add services to your account
Once you have an active account, you can add services to your account by selecting the option "Manage Services" at http://webservices.daehosting.com/usagelog/adminpage.htm. The name of the service should be what you have in your psServiceName property. If the service is successfully added, you will get a return code greater than zero. Save that number; that represents the ID of the service and you will need it in order to call the functions to record and reset statistics.

4. Log statistics for your functions
In order to record the usage of your functions, you will need to import the web service class using the following WSDL: "http://webservices.daehosting.com/usagelog/UsageLogService.wso?WSDL".

After that you should create an object inside your cWebservice object to send the messages to.

Then, from inside each one of your webservice functions that you want to log statistics for, you will need to add a line like
Get wsUpdateInvoked of oWSUsageLogService C_MyAccountID "MySecretPassword" C_MyServiceID "MyWebServiceFunctionName" to iUsage

Replace the parameters in above function line with your own.

Once you have followed all 4 steps above, you will be able to view the statistics of your webservices via the option "Statistics" from the Adminpage --http://webservices.daehosting.com/usagelog/adminpage.htm



CONCLUSION
============
These two solutions are only alternatives that we built and have their pros and cons. In the first solution you will have extra files unrelated to your services in the same workspace (Con) but at the same time you will be able to control the information logged and modify your statistics reports as needed (Pro).

In the second solution, you will have the files hosted somewhere else and you don't have to worry about file size etc (Pro) but you cannot customize which piece of information is collected or the information generated by  the statistics report (Con).

You should test them both -- and even come up with your own solution based on these two -- and adopt the one that best would suit your needs.


Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu

Web Links Related to this Article
File WebServicesUsageStatistics.zip
URL=http://www.dataaccess.com/KBasePublic/Files/2315.WebServicesUsageStatistics.zip


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.