none
How can i define a ServiceHostFactory in the App.config file RRS feed

  • Question

  • Hi,

    I'm quite new to WCF. I planned to host a few RestFul WCF Services via IIS. Everything works fine but i have one big issue, where i cannot go further:

    Since i decided to use SSL and Basic Authentication for security, i had to write a custom ServiceHostFactory with an Interceptor.

    Now everything is working fine with the following .svc file <%@ ServiceHost Service="Service.UserService" Factory="Service.CustomServiceHostFactory" %>.

    But as my understanding is, the .svc file is always generated new, if i publish my service via Visual Studio.

     

    My issue is simple: Is there a way to define the part 'Factory="Service.CustomServiceHostFactory" ' in my App.config file, so that its always correctly built and published???

    I tried it with

            <host>

              <baseAddresses>

                <add baseAddress="https://localhost:30/"/>

              </baseAddresses>

            </host>

    but there seem to be no possibility to define the factory.

     

    Can someone please help me? Please tell me, if something is not clear.

     

    Thanks,

    Jakob

    Wednesday, April 27, 2011 12:20 PM

Answers

  • Hi Pablo,

    Well, your answer helped me to find the answer i was searching for. This did not really work for me, because i do not have an ASP.NET application, but it gave me the hint to try playing with <serviceHostingEnvironment> and that works exactly the way i wannted to have!!!!

    Here is the way i implemented it in my App.config:

    <system.serviceModel>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true">

          <serviceActivations>

            <add relativeAddress="Service.svc" service="Service.Service1" factory="Service.CustomServiceHostFactory"/>

          </serviceActivations>

        </serviceHostingEnvironment>

        <services>

    .....

        </services>

    </system.serviceModel>

     

    Thank you for your inspiration, Pablo!

     

    • Marked as answer by Jakob007 Wednesday, April 27, 2011 1:31 PM
    Wednesday, April 27, 2011 1:30 PM

All replies

  • Hi Jakob,

    You don't need svc files anymore with WCF REST to expose your services. You can use ASP.NET Routes to configure your service URL and the WCF service host factory you want to use. Here is a post with more details of how to do that, http://www.kongsli.net/nblog/2011/04/06/adding-wcf-rest-services-to-existing-asp-net-web-application/

    Thanks

    Pablo.


    Pablo Cibraro - http://weblogs.asp.net/cibrax
    • Marked as answer by Jakob007 Wednesday, April 27, 2011 1:11 PM
    • Unmarked as answer by Jakob007 Wednesday, April 27, 2011 1:32 PM
    Wednesday, April 27, 2011 12:58 PM
  • Hi Pablo,

    Thank you for the fast answer. I will check it and let you know if that works!

     

    Thanks,

    Jakob

    Wednesday, April 27, 2011 1:12 PM
  • Hi Pablo,

    Well, your answer helped me to find the answer i was searching for. This did not really work for me, because i do not have an ASP.NET application, but it gave me the hint to try playing with <serviceHostingEnvironment> and that works exactly the way i wannted to have!!!!

    Here is the way i implemented it in my App.config:

    <system.serviceModel>

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true">

          <serviceActivations>

            <add relativeAddress="Service.svc" service="Service.Service1" factory="Service.CustomServiceHostFactory"/>

          </serviceActivations>

        </serviceHostingEnvironment>

        <services>

    .....

        </services>

    </system.serviceModel>

     

    Thank you for your inspiration, Pablo!

     

    • Marked as answer by Jakob007 Wednesday, April 27, 2011 1:31 PM
    Wednesday, April 27, 2011 1:30 PM