Navigation:  Server-side features >

Invocation Monitoring

Previous pageReturn to chapter overviewNext page

WebORB provides a flexible mechanism for injecting custom code into the invocation processing chain. Using .NET method attributes application developers can add custom logic to run before and after remote method invocations. To add pre- and post-invocation handling, create a .NET Attribute subclass and implement the Weborb.IWebORBAttribute interface as shown below:

using System;
using System.Reflection;
using System.Collections;
using Weborb;
using Weborb.Util.Logging;
 
namespace ORBExamples
{
   public class InvocationObserver : Attribute, IWebORBAttribute
   {
       public void HandlePreInvoke( MethodInfo method,
                                    object targetObj,
                                    object[] arguments )
       {
           Log.log( LoggingConstants.INFO, "before invocation of method " + method.Name );
       }
 
       public Hashtable HandlePostInvoke( MethodInfo method,
                                          object targetObj,
                                          object[] arguments,
                                          object returnValue,
                                          bool isException )
       {
           Log.log( LoggingConstants.INFO, "after invocation of method " + method.Name );
           return null;
       }
   }
}

 

The following code adds the InvocationObserver attribute to a method:

namespace ORBExamples.Invocations
{
   public class MonitoredService
   {
       [InvocationObserver]
       public string HelloWorld()
       {
           return "hello world";
       }
   }
}

When WebORB handlers an invocation of the HelloWorld() method, it invokes the HandlePreInvoke method from the InvocationObserver class first, then calls the HelloWorld() method and finally invokes the HandlePostInvoke.