public void ApplyDispatchBehavior(OperationDescription operationDescription,
System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation)
{
// Override default Behavior
dispatchOperation.Invoker = new FacadeOperationInvoker(
dispatchOperation.Invoker,
operationDescription);
}
public object Invoke(object instance, object[] inputs, out object[] outputs)
// Action Scheme is the following :
// Assembly/ClassName/MethodName/MethodNameOverloadedIfNecessaryElseSameName
String[] scheme = operationDescription.Messages[0].Action.Split("/".ToCharArray());
Object returnValue = null;
if (scheme.Length != 4)
throw new ApplicationException("Error in method execution according this action : "
+ operationDescription.Messages[0].Action);
// First Step : the assembly
Assembly assemb = Assembly.LoadFrom(
String.Format("{0}\\{1}.dll",
ConfigurationManager.AppSettings["DirectoryToMonitor"],
scheme[0])
);
if (null != assemb)
// Second Step : the type
Type t = assemb.GetType(scheme[1]);
if (null != t)
// Third step : create the instance
Object obj = Activator.CreateInstance(t);
// Fourth step : execute the method
returnValue = obj.GetType().InvokeMember(scheme[2], BindingFlags.InvokeMethod, null, obj, inputs);
// Fifth step : Manage output values. In fact, output values are not managed in this sample!
outputs = new Object[0];
else
throw new Exception(String.Format("Type {1} in Assembly {0} not found", scheme[0], scheme[1]));
throw new Exception(String.Format("Assembly {0} not found", scheme[0]));
return returnValue;