views:

1035

answers:

1

I have a WCF service that is setup to be hosted within a unity container. I was intending to use this container to perform method interception. The only issue is I can get my interceptor to fire...

first here the def of my interceptor attribute and handler

[AttributeUsage(AttributeTargets.Method)]
public class PCSecurityAttribute : HandlerAttribute
{
    public PCSecurityAttribute(Modules module, int modulePermission)
    {
        SecurityModule = module;
        SecurityModulePermission = modulePermission;
    }

    public Modules SecurityModule
    {
        get;
        set;
    }

    public int SecurityModulePermission
    {
        get;
        set;
    }

    public override ICallHandler CreateHandler(IUnityContainer container)
    {
        return new PCSecurityCallHandler(0, SecurityModule, 
           SecurityModulePermission);
    }
}

using System.ServiceModel.Security;
using MHC.PracticeConnect.Contract.Data.Security;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace MHC.PracticeConnect.Service
{
    public class PCSecurityCallHandler : ICallHandler
    {
        private Modules securityModule;
        private int securityModulePermission;

        public PCSecurityCallHandler(Modules module, int modulePermission)
        {
            securityModule = module;
            securityModulePermission = modulePermission;
            Order = 0;
        }

        public PCSecurityCallHandler(int order, Modules module, 
            int modulePermission)
        {
            securityModule = module;
            securityModulePermission = modulePermission;
            Order = order;
        }

        public IMethodReturn Invoke(IMethodInvocation input,
            GetNextHandlerDelegate getNext)
        {
            bool validPermission = false;
            // check security permission

            IMethodReturn result;

            if (validPermission)
                result = getNext().Invoke(input, getNext);
            else
                throw new SecurityAccessDeniedException(
                    "The current user does not have security " +
                    "permissions to call this module.");

            return result;
        }

        public int Order
        {
            get;
            set;
        }
    }
}

In my host I've tried to configure it to use interception to no avail... HELP!!!!

public class DocumentTemplateServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, 
        Uri[] baseAddresses)
    {
        UnityServiceHost host = 
            new UnityServiceHost(serviceType, baseAddresses);
        UnityContainer unity = new UnityContainer();
        host.Container = unity;
        host.Container.AddNewExtension<Interception>(); ;
        host.Container.RegisterType<IDocumentTemplateService, 
            DocumentTemplateService>().Configure<Interception>().
        SetInterceptorFor<IDocumentTemplateService>(
            new TransparentProxyInterceptor());

        return host;
    }
}

what am i doing wrong here?

A: 

You might want to check out using WCF behaviors. Here's links that might be useful.

http://msdn.microsoft.com/en-us/magazine/cc136759.aspx

AND

http://www.global-webnet.net/blogengine/post/2009/01/03/Integrating-IIS-WCF-and-Unity.aspx

-Bryan

Bryan Corazza