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

Secure Web Services via Message oriented Middleware

Rate me:
Please Sign up or sign in to vote.
4.96/5 (43 votes)
1 May 200372 min read 336.7K   821   198  
Describes an approach for delivery of Soap Messages serialised using ASP.NET Web Client Services over MSMQ and MQ
// --------------------------------------------------------------------------------
// Module:      Service1.asmx.cs
// Author:      Administrator
// Date:        02 January 2003
// Description: Standard Service (in this case simply serving a HelloWorld API
//				and existing only to support WSDL and associated Proxy generation).
// --------------------------------------------------------------------------------
// $Archive: <VSS Path To File>/Service1.asmx.cs $
// $Revision: 1 $ changed on $Date: 02 January 2003 19:05 $
// Last changed by $Author: Administrator $
// --------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;					// For Event Logging
using System.Data;
using System.Runtime.InteropServices;		// For the COM interface definition and AutoDual
using System.Web;
using System.Web.Services;
using System.IO;
using System.Drawing;						// Images etc.
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;


// --------------------------------------------------------------------------------
// Namespace:   WSAltRoute
// Author:      Administrator
// Date:        02 January 2003
// Description: Encapsulates the aleternative route for a Soap Message
// --------------------------------------------------------------------------------
namespace WSAltRoute
{
	[Serializable()]
	public class Colour1
	{
		public string code;
		public string description;
		public string longdescription;
		public bool isActive;
		[NonSerialized()]
		public bool isInProduct;

		public Colour1()
		{
			code = "RED";
			description = "Red";
			longdescription = "Lucious red";
			isActive = true;
			isInProduct = true;
		}
	}


	/// <summary>WSAltRoute.Service1</summary>
    /// <author>Administrator</author>
    /// <date>02 January 2003</date>
    /// <remarks>Class for simple HelloWorld service</remarks>
    public class Service1 : System.Web.Services.WebService
	{
		public Service1()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#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

		/// <summary>WSAltRoute.Service1.HelloWorld</summary>
        /// <author>Administrator</author>
        /// <date>02 January 2003</date>
        /// <remarks>Basic Hello world message</remarks>
        /// <param name="name" type="string">Name of person to say Hi to</param>
        /// <returns type="string">Return string saying Hi</returns>
        [WebMethod]
		public string HelloWorld(string name)
		{
			return "Hello World of " + name + "HTTP";
		}

		[WebMethod]
		public string[] HelloWorldArr(string name)
		{
			string[] arrRes = new string[4];
			arrRes[0] = "Hello";
			arrRes[1] = "World";
			arrRes[2] = "of";
			arrRes[3] = name + "HTTP[Arr]";
			return arrRes;
		}

		[WebMethod]
		public byte[] ReturnImage()
		{
			byte[] bytImage = null;
			Bitmap newBitmap = null;
			Graphics g = null;

			try
			{
				// Create a bitmap on the fly
				newBitmap = new Bitmap(80,60,PixelFormat.Format32bppArgb);
				g = Graphics.FromImage(newBitmap);
				g.FillRectangle(new SolidBrush(Color.Aquamarine), new Rectangle(0,0,80,60));

				// Read a file
				MemoryStream msImage = new MemoryStream();

				// Save image to stream
				newBitmap.Save(msImage, ImageFormat.Gif) ;
				msImage.Position = 0;

				// Now load to a byte array for transport
				bytImage = new byte[msImage.Length];
				msImage.Read(bytImage, 0, bytImage.Length);
				msImage.Close();
			}
			catch(Exception)
			{
				// Just supress it
			}
			finally 
			{
				// Note well: Must dispose of graphics object
				// before disposing of the bitmap

				// Dispose of the graphics object we created
				// as its no longer needed
				if (null != g) 
				{
					g.Dispose();
				}

				// Typically we'd dispose of the bitmap here
				if (null != newBitmap)
				{
					newBitmap.Dispose();
				}
			}

			return bytImage;
		}

		[WebMethod]
		public void SendImage(byte[] bytImage)
		{
			FileStream fs = new FileStream("C:\\Temp\\SendImageHTTP.gif", FileMode.Create);
			fs.Write(bytImage, 0, bytImage.Length);
			fs.Close();
		}

		[WebMethod]
		public Colour1[] ReturnColours(int vintHowMany)
		{
			Colour1[] arrColours = new Colour1[vintHowMany];
			for (int i = 0; i < vintHowMany; i++)
			{
				arrColours[i] = new Colour1();
				arrColours[i].code = arrColours[i].code + i.ToString() + "HTTP";
			}

			return arrColours;
		}
	}
}

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
Web Developer
United Kingdom United Kingdom
I am the Technical Director for Myphones.com, which specialises in developing integrated VoIP products and services for the consumer and SME markets. Technology-wise, we are heavily into the 2nd generation WS stack atop .NET, and basically most things Microsoft, as well as C++ on Linux.

Comments and Discussions