2
votes

My objective is register a Windsor Container for my non-http WCF service. However I cannot seem to work out where to put the code to register and initialise the container.

I have tried putting ...

Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration"

... onto my ServiceHost declaration in my .svc file however this does not appear to cause the Application_Start() method in my Global.asax.cs to fire.

I have also tried putting a static method inside a class as follows...

public static void AppInitialize()
{
}

... however this method also does not fire.

The method received from Castle Windsor is...

Kernel was null, did you forgot to call DefaultServiceHostFactory.RegisterContainer() ?

I could really do with a code an example that shows exactly where to register the container. Additionally where do I dispose of the container.

Thanks.

3
have you seen this question? stackoverflow.com/q/8789043/23697stombeur
Check if @Anton answer is not correct. Maybe u r indeed using HTTP WCF, since you are mentioning global.asax.cs. If so consider his answer correct. I will upvoete him if that will be the case.Falcon

3 Answers

1
votes

This is not an AppInitialize problem. Something you should ensure that you do is to add the Castle.Facilities.WcfIntegration.WcfFacility to your container:

container.AddFacility<Castle.Facilities.WcfIntegration.WcfFacility>();

Once that has been added, all should work without getting this exception.

  • Jason
0
votes

Did you try a static constructor as opposed to a static method?

something like

static MyClass()
{
  // setup windsor
  WindsorContainer windsorContainer = new WindsorContainer();
  ..

}

Someone has discussed exactly what you are trying to achieve only with StructureMap - should be easy enough to swap out that for the Windsor bits....

http://lostechies.com/jimmybogard/2008/07/30/integrating-structuremap-with-wcf/

0
votes

I know this was asked some time ago, but here are a couple of pitfalls you might want to check.

  • Are your Global.asax and Global.asax.cs files correct? Does your Global.asax point to the correct codebehind file?
  • Is the signature of the protected void Application_Start(object sender, EventArgs e) method correct?
  • Can you get the Application_Start() to fire if you don't add any Castle Windsor specific code in there?

Global.asax can be added by right-clicking the project and finding the application global file . Make sure the .asax file includes

<%@ Application Codebehind="Global.asax.cs" Inherits="YourNamespace.Global" Language="C#" %>

and nothing else.

(If you found a solution on your on, add it an mark is as an answer. It'll be helpful for others.)