C# Code:
///<summary>
/// Summary description for BusinessPipe.
///</summary>
[WebService(Namespace="http://tempuri/")]
[XmlInclude(typeof(CustomerData)),XmlInclude(typeof(OrderData))]
publicclass BusinessPipe : System.Web.Services.WebService
{
//This should be set to the name of your
business logic assembly.
privateconststring BUSINESS_ASSEMBLY = "My.Business.Assembly";
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
///<summary>
/// Clean up any resources being used.
///</summary>
protectedoverridevoid Dispose( bool disposing
)
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
private Type AccessType(string typeName)
{
Type type = null;
Assembly assembly = System.Reflection.Assembly.Load(BUSINESS_ASSEMBLY);
if(assembly == null)
thrownew Exception("Could not find assembly
in BusinessPipe!");
type = assembly.GetType(BUSINESS_ASSEMBLY
+ "." + typeName);
if(type == null)
thrownew Exception("Could not find type!");
return type;
}
///<summary>
/// Executes a method on the Business Logic
and returns whatever object that
/// method returns.
///</summary>
///<param name="typeName">The
class in the Business Logic to reference.</param>
///<param name="method">The
method that you want to execute in the class.</param>
///<param name="arguments">The
arguments to send to the method.</param>
///<returns>The same object that the
business logic method returns.</returns>
[WebMethod]
publicobject ExecuteMethod(string typeName,
string method,
paramsobject[] arguments)
{
object returnObject = null;
Type type = AccessType(typeName);
try
{
returnObject = type.InvokeMember(method,
BindingFlags.Default | BindingFlags.InvokeMethod,
null, null, arguments);
}
catch
{
//Do some custom exception handling here.
throw;
}
return returnObject;
}
///<summary>
/// Executes a method on the Business Logic
and returns the same ArrayList that
/// the method returns.
///</summary>
///<param name="typeName">The
class in the Business Logic to reference.</param>
///<param name="method">The
method that you want to execute in the class.</param>
///<param name="arguments">The
arguments to send to the method.</param>
///<returns>The same object that the
business logic method returns.</returns>
[WebMethod]
public ArrayList ExecuteArrayMethod(string
typeName, string method,
paramsobject[] arguments)
{
ArrayList returnObject = null;
Type type = AccessType(typeName);
try
{
returnObject = type.InvokeMember(method,
BindingFlags.Default | BindingFlags.InvokeMethod,
null, null, arguments) as ArrayList;
}
catch
{
//Do some custom exception handling here.
throw;
}
return returnObject;
}
} |