Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / C#

Extensible WebService and its IE-Hosted Client

Rate me:
Please Sign up or sign in to vote.
4.97/5 (33 votes)
2 Nov 200313 min read 59.5K   615   49  
The article presents the design of a WebService consisting of a general part and add-ins to process user's requests of different types. Such architecture simplifies dedicated add-ins allowing them to share general part facilities.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Text;
using System.Xml;
using ProcessorData;
using Framework;
using InHouseServerSecurity;

namespace ExtensibleWS
{
	/// <summary>
	/// Summary description for Service1.
	/// </summary>
	[WebService(Namespace="http://ExtensibleWS")]
	public class WS : System.Web.Services.WebService
	{
		private ProcessorData.Data       data;
		private ProcessorData.Serializer srData;

		public WS()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();

			this.data = new Data();
			this.srData = new ProcessorData.Serializer(typeof(Data));
		}

		#region Component Designer generated code
		
		//Required by the Web Services Designer 
		private IContainer components = null;
				
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if(disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);		
		}
		
		#endregion


		[WebMethod]
		public string ProcessClient(string strSQLData)
		{
			try
			{
				this.data = (Data)this.srData.Deserialize(strSQLData);
			}
			catch
			{
				this.data = null;
				return null;
			}

			if (SecurityManager.Ref.Allowed)
			{
				try
				{
					if (SecurityManager.Ref.Check(this.data))
						ProcessorManager.Ref.Run(this.data);
				}			
				catch (Exception e)
				{
					this.data.Error = e.Message;
				}
			}
			else
				this.data.Error = "Server is not initialized.";		


			this.data.CommandText = null;		
			return this.srData.Serialize(this.data);
		}

		[WebMethod]
		public string ProcessAdmin(string strTask)
		{
			try
			{
				this.data = (Data)this.srData.Deserialize(strTask);
			}
			catch
			{
				this.data = null;
				return null;
			}
			
			try
			{
				if (!SecurityManager.Ref.Allowed)
				{
					SecurityManager.Ref.LoadConfig(this.data.CommandText);
					ProcessorManager.RootDir = SecurityManager.Ref.RootDir;
					ProcessorManager.Create();
					SecurityManager.Ref.Allowed = true;
				}
			}
			catch (Exception e)
			{
				this.data.Error = e.Message;	
			}

			this.data.CommandText = null;		
			return this.srData.Serialize(this.data);
		}
	}
}

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 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


Written By
Software Developer (Senior)
Israel Israel


  • Nov 2010: Code Project Contests - Windows Azure Apps - Winner
  • Feb 2011: Code Project Contests - Windows Azure Apps - Grand Prize Winner



Comments and Discussions