6

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!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Mark
  • 61
  • 1
  • 2

2 Answers2

4

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:

John Saunders
  • 160,644
  • 26
  • 247
  • 397
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • If I want (WCF service) to build a persistent socket connection with a host whenever WCF service starts, can you please suggest/advice on how to do so? As you mentioned in your answer that we shouldn't rely on a IIS-specific mechanism. – FaizanHussainRabbani Apr 25 '16 at 07:34
-1

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.

Adriaan de Beer
  • 1,136
  • 13
  • 23