none
How to host Custom ServiceHost in IIS RRS feed

  • Question

  • Hi,

    I have create Custom Service Host. I need this actulaly to put any configuration for my application such as Autommaper, Unity. etc

    public class CustomServiceHost : ServiceHost
    {
         public CustomServiceHost(Type t) : base(t) { }
    
         public CustomServiceHost() : base() {}
            
         protected override void OnOpening()
         {
             base.OnOpening();
    
             // Automapper Configuration
             // Unity Configuration
             // Any other configuration
         }
     }

    Now, I need to put this under IIS. Thatsway I create CustomServiceHostFactory and reference it in my svc file as below

    public class CustomServiceHostFactory : ServiceHostFactory
    {
         protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
         {
              ServiceHost host = new CustomServiceHost(typeof(Service.EmployeeImpl));
              return host;
         }
    }
    <%@ ServiceHost Factory="Service.Shared.CustomServiceHostFactory" Language="C#" Debug="true" Service="Service.EmployeeImpl" %>

    However, when I start the the IIS I got this error

    Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are []

    This error reference to this line on my CustomServiceHost class

    public CustomServiceHost(Type t) : base(t) { }

    Can anyone help me why I got this error?

    Here is my configuration file

      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <services>
          </service>
          <service name="Service.EmployeeImpl">
            <endpoint address="EmployeeService" binding="basicHttpBinding" bindingNamespace="http://ibisystems/grcsuite/2014/06" contract="Contract.Operation.IEmployee">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" bindingNamespace="http://ibisystems/grcsuite/2014/06" contract="IMetadataExchange" />
        </services>
      </system.serviceModel>

    Regards

    Thursday, July 17, 2014 8:57 AM

Answers

  • Hi,

    When hosting the WCF Service in the IIS, the creation of the services hosts is done automatically, based on a configuration file (Web.config), where the endpoints are defined. The Custom service hosts can also be used in this hosting environment, but they require some additional code in the form of a ServiceHostFactory, for more information, please try to refer to the following articles:
    #A Custom ServiceHostFactory in IIS:
    http://www.codeproject.com/Tips/29167/A-Custom-ServiceHostFactory .

    #Custom Service Host:
    http://msdn.microsoft.com/en-us/library/aa395224(v=vs.110).aspx .


    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.

    • Marked as answer by wapt49 Monday, July 21, 2014 12:50 PM
    Friday, July 18, 2014 10:02 AM
    Moderator

All replies

  • IIS host ASP.NET applications like ASP.NET UI(s), ASP.NET legacy Web services and ASP.NET WCF Web services. That's what IIS hosts.
    Friday, July 18, 2014 4:04 AM
  • Hi,

    When hosting the WCF Service in the IIS, the creation of the services hosts is done automatically, based on a configuration file (Web.config), where the endpoints are defined. The Custom service hosts can also be used in this hosting environment, but they require some additional code in the form of a ServiceHostFactory, for more information, please try to refer to the following articles:
    #A Custom ServiceHostFactory in IIS:
    http://www.codeproject.com/Tips/29167/A-Custom-ServiceHostFactory .

    #Custom Service Host:
    http://msdn.microsoft.com/en-us/library/aa395224(v=vs.110).aspx .


    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.

    • Marked as answer by wapt49 Monday, July 21, 2014 12:50 PM
    Friday, July 18, 2014 10:02 AM
    Moderator