Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Secure Web Services via TCP/IP

, 30 May 2003
Describes an approach for delivery of Soap Messages serialised using ASP.NET Web Client Services over TCP/IP
wsaltroute2.zip
ArgosAPIExtensions
Bin
Client
ArgosAPIExtensions.dll
WSAltRouteTest.exe
WSIPTransports.dll
Server
WebServices
WSAltRouteArgos
bin
ArgosAPIExtensions.dll
ArgosAPIExtensions.pdb
WSAltRouteArgos.dll
WSAltRouteArgos.pdb
Global.asax
WSAltRouteArgos.csproj.webinfo
WSAltRouteArgos.vsdisco
WSAltRouteBEFake.exe
WSAltRouteTest
App.ico
Web References
ArgosTrinketService
Reference.map
Service1.disco
Service1.wsdl
WSAltRouteBEFake
App.ico
WSAltTransports2
WSQTransports.dll
AsyncHelper.dll
// --------------------------------------------------------------------------------
// Module:      ProxyCommon.cs
// Author:      Simon G
// Date:        24 February 2003
// Description: Common functions for use by the Web Service caller
// --------------------------------------------------------------------------------
// $Archive: <VSS Path To File>/ProxyCommon.cs $
// $Revision: 1 $ changed on $Date: 24 February 2003 18:37 $
// Last changed by $Author: Simon G $
// --------------------------------------------------------------------------------
using System;
using System.Net;
using System.Web.Services.Protocols;


namespace WSAltRouteProxy
{
	using WSAltTransports;


	/// <summary>WSAltRouteProxy.ProxyCommon</summary>
    /// <author>SGregory</author>
    /// <date>16 January 2003</date>
    /// <remarks>
    /// Some shared functions for the Proxy classes.  This means that
    /// several generated proxies e.g. localhost1, localhost2 etc. can all
    /// share these routines.
    /// </remarks>
    public class ProxyCommon
	{
		// Common WebRequest stuff

		/// <summary>WSAltRouteProxy.ProxyCommon.SchemeIsSupported</summary>
        /// <author>Simon G</author>
        /// <date>24 February 2003</date>
        /// <remarks>Checks for a supported scheme</remarks>
        /// <param name="vUri" type="System.Uri">Uri containing scheme</param>
        /// <returns type="bool">true if the scheme passed is known</returns>
        /// <postconditions>true if known</postconditions>
        static public bool SchemeIsSupported(
			Uri vUri)
		{
			// Here we check see if the scheme is one of a known number
			bool blnIsSupported = (vUri.AbsoluteUri.IndexOf("msmq://") >= 0 ||
								   vUri.AbsoluteUri.IndexOf("mq://") >= 0 ||
								   vUri.AbsoluteUri.IndexOf("ip://") >= 0);
			return blnIsSupported;
		}


		/// <summary>WSAltRouteProxy.ProxyCommon.RegisterRelevantScheme</summary>
		/// <author>Simon G</author>
		/// <date>02 February 2003</date>
		/// <remarks>
		/// This method checks for specific protocols we support and registers it
		/// if needs be.  For Uri's sarting "http://", etc. no registration is required.
		/// </remarks>
		/// <param name="uri" type="System.Uri">The Uri the call involves</param>
		/// <param name="client" type="System.Web.Services.Protocols.SoapHttpClientProtocol">The caller (generated proxy)</param>
		/// <returns type="IWebRequestCreate">An instance of a request creator if thr Uri is queue based</returns>
		/// <preconditions>
		/// Uri scheme (protocol) is either already known (e.g. "HTTP://" and hence does not 
		/// need to be registered, or is a supported custom one - like MQ:// or MSMQ:// in our case.
		/// </preconditions>
		/// <postconditions>Non-standard protocol </postconditions>
		static public IWebRequestCreate RegisterRelevantScheme(
			Uri uri, 
			SoapHttpClientProtocol client)
		{
			// Check for any custom Uri schemes we support.
			// We need to register these ones...or calls using them will be rejected.
			string strNewScheme = string.Empty;
			IWebRequestCreate iWebReq = null;

			if (uri.AbsoluteUri.ToLower().IndexOf("msmq:") == 0)
			{
				// Create an instance of the "msmq:" WebRequest factory
				strNewScheme = "msmq";
				iWebReq = new MSMQRequestCreator();

				// Pass the Response Uri too - if it's valid
				if (((ISoapClientProtocol)client).ResponseUrl != null &&
					((ISoapClientProtocol)client).ResponseUrl.Trim().Length > 0)
					((MSMQRequestCreator)iWebReq).ResponseUri = new Uri(((ISoapClientProtocol)client).ResponseUrl);
			}
			else
			if (uri.AbsoluteUri.ToLower().IndexOf("mq:") == 0)
			{
				// Create an instance of the "mq:" WebRequest factory
				strNewScheme = "mq";
				iWebReq = new MQRequestCreator();

				// Pass the Response Uri too - if it's valid
				if (((ISoapClientProtocol)client).ResponseUrl != null &&
					((ISoapClientProtocol)client).ResponseUrl.Trim().Length > 0)
					((MQRequestCreator)iWebReq).ResponseUri = new Uri(((ISoapClientProtocol)client).ResponseUrl);
			}
			else
			if (uri.AbsoluteUri.ToLower().IndexOf("ip:") == 0)
			{
				// Create an instance of the "ip:" WebRequest factory
				strNewScheme = "ip";
				iWebReq = new IPRequestCreator();

				// We don't support a Response Url for IP
			}

			// Do we wish to register anything?
			if (iWebReq != null)
			{
				// Register the appropriate scheme here for WebRequest
				WebRequest.RegisterPrefix(
					strNewScheme, 
					iWebReq);
			}

			// Return the specialist request creator - we may not have one though!
			return iWebReq;
		}


		/// <summary>WSAltRouteProxy.ProxyCommon.GetWebRequest</summary>
		/// <author>SGregory</author>
		/// <date>16 January 2003</date>
		/// <remarks>
		/// Called from the overridden GetWebRequest within the generated WS proxy.
		/// This method checks for specific protocols we support and registers it
		/// if needs be.  For Uri's sarting "http://", etc. no registration is required -
		/// the specific WebRequest instance can just be created.
		/// </remarks>
		/// <param name="uri" type="System.Uri">The Uri the call involves</param>
		/// <param name="client" type="System.Web.Services.Protocols.SoapHttpClientProtocol">The caller (generated proxy)</param>
		/// <returns type="System.Net.WebRequest">The cast base class version of the specific protocol handler.</returns>
		/// <preconditions>
		/// Uri scheme (protocol) is either already known (e.g. "HTTP://" and hence does not 
		/// need to be registered, or is a supported custom one - like MQ:// or MSMQ:// in our case.
		/// </preconditions>
		/// <postconditions>Relevant WebRequest created</postconditions>
		static public WebRequest GetWebRequest(
			Uri uri, 
			SoapHttpClientProtocol client)
		{
			// Check for any custom Uri's we support.
			// We need to register the custom ones
			//RegisterRelevantScheme(
			//	uri,
			//	client);
			
			IWebRequestCreate iWebReqCreator = RegisterRelevantScheme(
				uri,
				client);

			// Create a WebRequest dependent on URI scheme
			// Note - if we get here, we're in one of 3 modes:
			//
			//	1) We are a Uri with well known scheme e.g. http://
			//	2) We are a Uri not so well known but we've been registered above e.g. msmq://
			//	3) We are a Uri even less well known e.g. mailto: and are not supported.
			//     In this 3rd case, the following call to WebRequest.Create() will fail
			//	   with "Uri scheme not supported" or similar.
			//
			// This next call against the WebRequest base class forces the IWebRequestCreate
			// interface to be called for the relevant scheme.
			WebRequest newWebRequest = null;

			// Assuming we had a creator created, lets use it to create the request
			if (iWebReqCreator != null)
				newWebRequest = iWebReqCreator.Create(uri);
			else
				// For a non-Queued Uri, create the standard way
				newWebRequest = WebRequest.Create(uri);

			// If we get here, pass the callers wait timeout (in secs)
			newWebRequest.Timeout = client.Timeout;

			// Return the specific WebRequest instance
			return newWebRequest;
		}


		/// <summary>WSAltRouteProxy.ProxyCommon.GetWebResponse</summary>
		/// <author>SGregory</author>
		/// <date>17 January 2003</date>
		/// <remarks>Invokes the WebResponse logic of the specific protocol handler</remarks>
		/// <param name="webReq" type="System.Net.WebRequest">Specific WebRequest handler e.g. MSMQWebRequest</param>
		/// <returns type="System.Net.WebResponse">Specific WebResponse object</returns>
		static public WebResponse GetWebResponse(
			WebRequest webReq)
		{
			// Ask for a response for the request - any exceptions will be thrown straight through
			// this method and to our caller
			return webReq.GetResponse();
		}
	}
}

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

Share

About the Author

Simon Gregory
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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 31 May 2003
Article Copyright 2003 by Simon Gregory
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid