Click here to Skip to main content
15,886,873 members
Articles / Web Development / ASP.NET

Monitor your Web Services usage via .NET SOAP Extensions

Rate me:
Please Sign up or sign in to vote.
4.98/5 (48 votes)
6 Apr 2009CPOL27 min read 110.4K   3K   167  
This article demonstrates how you can monitor usage of your Web Services using .NET and SOAP Extensions.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace WSDM_WebServices
{
	/// <summary>
	/// Summary description for Subscribe.
	/// </summary>
	public class Subscribe : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnSubscribe;


		private string connectionString;
		private string subscriptionMode;	// Trial/Full
		private string subscriptionPackage; // Standard/Premium/Promo
		protected System.Web.UI.WebControls.DropDownList ServiceName;
		protected System.Web.UI.WebControls.TextBox RegistrationKey;
		protected System.Web.UI.WebControls.RadioButtonList rbSubscriptionMode;
		protected System.Web.UI.WebControls.RadioButtonList rbSubscripPackage;
		protected System.Web.UI.WebControls.TextBox txtSubscriptParam;
		protected System.Web.UI.WebControls.Label lblSubscriptParam;
		protected System.Web.UI.WebControls.Label Msg;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2; // Standard/Premium/Promo
		private int subscriptionParam;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			connectionString = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"); 
			string sql = "SELECT * FROM WSDM_Services";

			SqlConnection conn = new SqlConnection( connectionString );
			SqlCommand command = new SqlCommand( sql, conn );
			
			if (!IsPostBack)
			{
				conn.Open();
				SqlDataReader reader = command.ExecuteReader();
				this.ServiceName.DataTextField = "ServiceName";
				this.ServiceName.DataValueField = "ServiceName";
				this.ServiceName.DataSource = reader;
				this.ServiceName.DataBind();
				conn.Close();

				// Full version as default subscription mode
				rbSubscriptionMode.SelectedIndex = 1;

				// prepaid as default package 
				rbSubscripPackage.SelectedIndex = 0;
			}
			UpdateUIElementsAndVariables();
			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSubscribe.Click += new System.EventHandler(this.btnSubscribe_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSubscribe_Click(object sender, System.EventArgs e)
		{
			try
			{
				DBManager db = new DBManager(connectionString);
				
				if ( txtSubscriptParam.Text == "" || rbSubscriptionMode.SelectedIndex == 0)
					subscriptionParam = -1;
				else
					subscriptionParam = Convert.ToInt32(txtSubscriptParam.Text);

				int x = db.SubscribeUser(RegistrationKey.Text, ServiceName.SelectedItem.Text, subscriptionMode,
							subscriptionPackage, subscriptionParam);
			}
			catch( SqlException exp)
			{
				Msg.Text = exp.Message;

			}
			catch(Exception exp)
			{
				Msg.Text = exp.Message;
			}
		}

		private void SubscriptionMode_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			
			UpdateUIElementsAndVariables();
		}

		private void rbSubscripPackage_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			UpdateUIElementsAndVariables();
		}

		private void UpdateUIElementsAndVariables()
		{
			if ( rbSubscriptionMode.SelectedIndex == 0 )
			{
				subscriptionMode = "Trial";
				subscriptionPackage = "None";
				txtSubscriptParam.Enabled = false;
				rbSubscripPackage.Enabled = false;
			}
			else
			{
				subscriptionMode = "Full";
				txtSubscriptParam.Enabled = true;
				rbSubscripPackage.Enabled = true;
				switch (rbSubscripPackage.SelectedIndex)
				{
					case 0:
						subscriptionPackage = "Standard";
						lblSubscriptParam.Text = "Number of calls";
						break;
					case 1:
						subscriptionPackage = "Premium";
						lblSubscriptParam.Text = "Number of days";
						break;
					case 2:
						subscriptionPackage = "Promo";
						lblSubscriptParam.Text = "Number of calls";
						break;
				}

			}
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect
Canada Canada
Kamran Bilgrami is a seasoned software developer with background in designing mission critical applications for carrier grade telecom networks. More recently he is involved in design & development of real-time biometric based security solutions. His areas of interest include .NET, software security, mathematical modeling and patterns.

He blogs regularly at http://WindowsDebugging.Wordpress.com

Comments and Discussions