none
How can I specify a ServiceHostFactory in app.config?

    Question

  • Is there a way I can specify a ServiceHostFactory in an app.config file?  I have a custom ServiceHostFactory class for instantiating ServiceHosts with particular configurations.  This works fine when I create them programmatically, but when debugging in the IDE, the services are started from the app.config file and without the custom configuration done by the factory, they aren't useful for debugging.
    Thursday, August 13, 2009 6:40 PM

Answers

  • Hi,

    Ok.... now I get you.
    I don't think this is possible with the built-in WcfSvcHost.exe .... you'd need to create your own host process (for example a Console application or whatever application) that uses your ServiceHost-derived class.

    Also remember, that you can host your service in any host or application (including Cassini) and use the WcfTestClient.exe tool to easily test your service.
    When you press F5, VisualStudio is hosting the service with WcfSvcHost.exe and it's opening the WcfTestClient.exe tool to test the service... you can customize the hosting part using your custom ServiceHost keeping the same test client tool for quick testing.

    Regards,
    Rodrigo.
    Friday, August 14, 2009 6:27 PM

All replies

  • Hi,

    I don't really understand what's the problem.... what do you mean with "... when debugging in the IDE, the services are started from the app.config"?

    If your service is self-hosted you always create the ServiceHost programmatically (you don't even need a factory there). The ServiceHostFactory is useful when hosting a service by using a .svc file, in that case you can set the factory type by using the following directive in the .svc file: <%@ ServiceHost Factory="MyHostFactory" ... %>

    Regards,
    Rodrigo.
    Friday, August 14, 2009 2:08 AM
  • If a WCF service library solution is run from the IDE, it is hosted inside Cassini or whatever the built-in webserver is called.  I would like to be able to do that for quick and dirty testing and debugging purposes, but that process is governed by the app.config file.  I can't figure out how to get it to instantiate its host container using my custom ServiceHostFactory class.

    Friday, August 14, 2009 4:45 PM
  • Hi,

    Ok.... now I get you.
    I don't think this is possible with the built-in WcfSvcHost.exe .... you'd need to create your own host process (for example a Console application or whatever application) that uses your ServiceHost-derived class.

    Also remember, that you can host your service in any host or application (including Cassini) and use the WcfTestClient.exe tool to easily test your service.
    When you press F5, VisualStudio is hosting the service with WcfSvcHost.exe and it's opening the WcfTestClient.exe tool to test the service... you can customize the hosting part using your custom ServiceHost keeping the same test client tool for quick testing.

    Regards,
    Rodrigo.
    Friday, August 14, 2009 6:27 PM