Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hooking into AppInitialize with WCF service

I'm having issues with my WCF service. I need to do a windsor container injection pre application_start and noticed I can use the AppInitialise method. It works on visual studio debug but when I deploy to IIS the code does not get fired.. I initialized the class as follows

public static class Class1
{
    public static void AppInitialize()
    {
        IWindsorContainer container;
        container = new WindsorContainer("windsor.xml");
        container.AddFacility<WcfFacility>();
        container.Resolve<ProfileLookUpService>();
    }
}

Is there any special task I need to do to get this to work on IIS. I'm using version 6.

Thanks!

like image 316
Mark Avatar asked Mar 25 '10 17:03

Mark


1 Answers

Well, you need to be aware of several things:

  • a WCF service could be self-hosted - it's not always hosted in IIS, so don't rely on a IIS-specific mechanism, if ever possible

  • a WCF service on the server-side basically consists of a ServiceHost (or a custom descendant thereof), which initializes the WCF runtime, and it will create service class instances as needed to handle the requests

So it really depends on where you want to inject your stuff - my gut feeling would tell me you're probably interested in the ability to create a custom ServiceHost descendant, and hook into some of its methods and events to handle your initialization.

Check out some really good articles and blog post on the topic here:

  • How to Initialize Hosted WCF Services
  • Castle Windsor and non-HTTP Protocol WCF Services
like image 137
marc_s Avatar answered Nov 04 '22 18:11

marc_s