|
using System;
using System.IO;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Data;
using WSDM_WebServices;
namespace UserValidation
{
/// <summary>
/// Summary description for UserValidationExtension.
/// </summary>
///
// configuration parameter
public class UserValidationExtension : SoapExtension
{
private string connectionString;
public override object GetInitializer(System.Type serviceType)
{
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
WSDM_Configuration config = new WSDM_Configuration();
config.connectionString = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
return config;
}
public override void Initialize(object initializer)
{
WSDM_Configuration param = (WSDM_Configuration)initializer;
connectionString = param.connectionString;
return;
}
public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
{
switch(message.Stage)
{
case SoapMessageStage.BeforeSerialize:
break;
case SoapMessageStage.AfterSerialize:
break;
case SoapMessageStage.BeforeDeserialize:
break;
case SoapMessageStage.AfterDeserialize:
// Initialize the RegKey
string regKey = "";
try
{
// Loop through the Soap headers in the message
foreach (SoapHeader aHeader in message.Headers)
{
// If it's our header (decalared in DBManager),
// get the RegisterationKey and assign it to RegKey
if (aHeader is ClientMessageHeader)
{
ClientMessageHeader newHeader = (ClientMessageHeader)aHeader;
regKey = (string)newHeader.RegistrationKey;
}
}
// If RegKey is still blank, throw a SOAP exception
if (regKey == "" || regKey == null)
throw new CustomSoapException("No registration key supplied");
// Call ValidateUser, and throw an exception if not successful
if (ValidateUser(message.MethodInfo.Name,regKey) == 0)
return;
else
throw new CustomSoapException("Invalid account details supplied");
}
catch(CustomSoapException ex)
{
throw ex;
// not shown here but its a good idea to log the exceptions for any further investigations needed
}
catch(SoapException ex)
{
throw new SoapException("Unknown error encountered", SoapException.ServerFaultCode);
// not shown here but its a good idea to log the exceptions for any further investigations needed
}
catch(Exception ex)
{
throw new SoapException("Unknown error encountered", SoapException.ServerFaultCode);
// not shown here but its a good idea to log the exceptions for any further investigations needed
}
}
}
private int ValidateUser(string serviceName, string RegKey)
{
DBManager db = new DBManager(connectionString);
int x = db.ValidateUser(serviceName, RegKey);
return x;
}
}
}
|
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.
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