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 WindsorConta开发者_如何学运维iner("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!
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
If AppInitialize() is not called upon startup in your deployment server, then most likely you have not enabled WCF Non-Http activation on that server.
Go to control panel > Program and Features > Turn Windows features on or off and then look for ‘Microsoft .NET Framework 3.5.1’. Under this option, ensure that the Windows Communication Foundation Non-HTTP Activation option is installed.
精彩评论