Policy Injection and Remoting

Topics: Policy Injection Application Block
Oct 20, 2010 at 11:58 AM
Edited Oct 20, 2010 at 12:06 PM

Hi All,

Well I really need help with this. I was using PostSharp 1.5 to do my related AOP stuff, but since they moved to version 2.0, they changed the licencing, thus it is no longer an option. So I moved to the Policy Injection block, which I am still trying to implement. So far it has been a really big nightmare, Postsharp is so my easy and readble. The way things work with PIAB really sucks (sorry about the languange). Anyway here is the code I am using:

SERVER

namespace PT.MatchProfiler.MediaVision.Server.Aop
{
    [AttributeUsage(AttributeTargets.All)]
    [ConfigurationElementType(typeof(CustomCallHandlerData))]
    public class EnableSessionHandler : HandlerAttribute, ICallHandler
    {
        /////////////////////////////////
        //         Constructors        //
        /////////////////////////////////

        public EnableSessionHandler()
        { }

        /////////////////////////////////

        public EnableSessionHandler(NameValueCollection collection)
        { }


        /////////////////////////////////
        //           Methods           //
        /////////////////////////////////

        public IMethodReturn Invoke(IMethodInvocation pMethodInvocation, GetNextHandlerDelegate pGetNextHandlerDelegate)
        {
            IMethodReturn objMsg = pGetNextHandlerDelegate()(pMethodInvocation, pGetNextHandlerDelegate);


            return objMsg;
        }

        /////////////////////////////////

        public static void ProcessException(Exception pEx)
        {

        }

        public override ICallHandler CreateHandler(Microsoft.Practices.Unity.IUnityContainer container)
        {
            return new EnableSessionHandler();
        }
    }
}

namespace PT.MatchProfiler.MediaVision.Server
{
    [EnableSessionHandler]
    public abstract class AServerObject : MarshalByRefObject, IServerObject, ISponsor
    {
    }
    [EnableSessionHandler]
    public class MediaVisionSession : AServerObject, IMediaVisionSession, ITrackingHandler
    {
        /////////////////////////////////
        //           Members           //
        /////////////////////////////////

        private IStorageModule objStorageModule = null;
        private bool bIsLogged = false;
        private string strErrorMessage = "";


        /////////////////////////////////
        //         Constructors        //
        /////////////////////////////////

        public MediaVisionSession(string pErrorMessage)
        {
            this.strErrorMessage = pErrorMessage;
        }

        /////////////////////////////////

        public MediaVisionSession(IClientSession pClientSession)
        {
            this.objClientSession = pClientSession;

            TrackingServices.RegisterTrackingHandler(this);

            LifetimeServices.LeaseManagerPollTime = TimeSpan.FromSeconds(20);

            this.bIsLogged = true;
        }


        /////////////////////////////////
        //          Properties         //
        /////////////////////////////////

        public INetworkModule NetworkModule
        {
            get
            {
                lock (this)
                {
                    if (this.objNetworkModule == null)
                    {
                        this.objNetworkModule = PolicyInjection.Wrap<INetworkModule>(new NetworkModule(this.objClientSession));
                    }

                    return this.objNetworkModule;
                }
            }
        }

        //////////////////////////////////

        public IStorageModule StorageModule
        {
            get
            {
                lock (this)
                {
                    if (this.objStorageModule == null)
                    {
                        this.objStorageModule = PolicyInjection.Wrap<IStorageModule>(new StorageModule(this.objClientSession));
                    }


                    this.objStorageModule.GetVirtualDisks();//Works here but not on the client

                    return this.objStorageModule;
                }
            }
        }

        //////////////////////////////////
      
        public IApplicationCommandLine ApplicationCommandLine
        {
            get
            {
                return null;
            }
        }

        //////////////////////////////////

        public bool IsLogged
        {
            get
            {
                return this.bIsLogged;
            }
        }

        //////////////////////////////////

        public string ErrorMessage
        {
            get
            {
                return this.strErrorMessage;
            }
        }


        /////////////////////////////////
        //           Methods           //
        /////////////////////////////////

        [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.Infrastructure)]
        public void DisconnectedObject(object obj)
        {
            this.ClientSession.Exit();
        }

        /////////////////////////////////

        [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.Infrastructure)]
        public void MarshaledObject(object obj, ObjRef or)
        { }

        /////////////////////////////////

        [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.Infrastructure)]
        public void UnmarshaledObject(object obj, ObjRef or)
        { }

        /////////////////////////////////

        public void KeepSessionAlive()
        {
            ((ClientSession)this.objClientSession).UpdateSessionTime();
        }

        //////////////////////////////////
    }
}

This fails on the client side:

List<IVirtualDisk> objDisks = GlobalSettings.MediaVisionSession.StorageModule.GetVirtualDisks();

It says it can't convert the proxy to the type. Well something is happening to the GlobalSettings.MediaVisionSession.StorageModule, because the proxy returned by the remoting is not vaalid anymore.

Any help will be more than welcome.

Thanks



Oct 21, 2010 at 1:14 AM

Could you post the exact error message?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 21, 2010 at 11:53 AM

Hi Sarah,

Thanks for the reply. I can´t remenber the exact error message but it was some kind of a generic remoting exception in which it was not able to cast the object... I can´t replicated it now, because we bought the license for the Postsharp 2.0.

It is way easier, as for me this unity stuff is simple not worth.

Thanks,

 

Marco