none
WCF AutoStart AppFabric -> OnServiceActivated called Twice RRS feed

  • Question

  • I have implemented a WCF service with the intention of it running on Application Pool startup with a single instance and then for some web pages to query it for some data whenever.

    I notice some odd behaviour on Application Pool startup and I cannot figure out why it is happening.

    I am using AppFabric and have configured my WCF service to AutoStart and I use a class to autoStart my application with an OnServiceActivated function.

    What I see happening every time is that OnServiceActivated is called once, I perform all my initialisation etc and start my application and then it gets called again a few seconds afterwards. This is causing me some real problems as I initialise some communications and the second instance is unable to establish the communication due to the first instance doing so.

    Any ideas why it is being called twice? Any suggestions on trying to find out why?

    thanks

    Also I think the first instance is being terminated somehow as I can see the communications stop but it looks like the connect is still active 


    • Edited by Chris Draycott Wednesday, January 14, 2015 4:47 PM Additional text
    Wednesday, January 14, 2015 4:44 PM

Answers

All replies

  • Hi Chris Draycott,

    First please try to make sure that you have configured WCF Service to AutoStart in AppFabric very well by checking the following article:
    #WCF and AppFabric Auto-Start:
    http://blogs.msdn.com/b/rjacobs/archive/2010/12/09/wcf-and-appfabric-autostart.aspx .

    Then please try to use the fiddler to help you get the detailed request and response information.
    #Fiddler:
    http://www.telerik.com/fiddler .

    Best Regards,
    Amy Peng



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 15, 2015 6:10 AM
    Moderator
  • Amy,

    I have followed the guide in the link and used a custom service factory, referenced this in the svc markup and I get exactly the same behaviour.

    If I configure my service to AutoStart, my CreateServiceHost function gets called twice. This is causing me real problems as I initialise communications to some devices and this happening twice causes problems.

    Also one instance knows nothing about the other. I tried having a Boolean setting in the ServiceHostFactory that  got set when it was started and it was not set on the second instance.

    How can I avoid the startup code being called twice? Why is it being called twice?

    I don't need to check fiddler as this is before any calls are made on my WCF service. This is simply on enabling AutoStart for my service or on restart of the AppDomain.

    Any help much appreciated.

    Monday, January 26, 2015 4:58 PM