none
From console application to hosting a WCF service in IIS 7.5 (web.config related problem) RRS feed

  • Question

  • Hello.

    I've been working on a WCF service for a few weeks now and it has been working great as a self-hosted service in a console application environment.

    Today I decided to try and host it with IIS 7.5 using a custom ServiceHostFactory. 

    My .svc file looks like this:

    <%@ ServiceHost Language="C#" Debug="true" Service="WCF_Service.CubeService" Factory="IISHost.CubeHostFactory" %>

    Below is my entire web.config (sorry for the mess)

    <?xml version="1.0"?>
    <configuration>
     <!--<authorization>
     <allow users="*"/>
     <deny users="?"/>
     </authorization>-->
     
     <system.web>
     <compilation debug="true" targetFramework="4.0" />
     </system.web>
     
     <system.serviceModel>
     <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
      logMessagesAtTransportLevel="true" />
      <endToEndTracing activityTracing="false" messageFlowTracing="false" />
      </diagnostics>
     
     <behaviors>
     <serviceBehaviors>
     
     <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
     </behavior>
      <behavior name="Default">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior> 
      
     </serviceBehaviors>
    
     <endpointBehaviors>
      <behavior name= "SilverlightFaultBehavior">
      <silverlightFaults />
      </behavior>
     </endpointBehaviors>
     
     </behaviors>
     
     <extensions>
     <behaviorExtensions>
     <add name="silverlightFaults"
      type="WCF_Service.Service_Behavior.SilverlightFaultBehavior, Service Implementation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
     </behaviorExtensions>
     </extensions>
    
     <bindings>
     <basicHttpBinding>
     <binding name="CustomHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:10:00"> 
     </binding>
     </basicHttpBinding>
     </bindings>
    
     <services>
     <service name="WCF_Service.CubeService" behaviorConfiguration="Default">
     <endpoint address=""
       binding="basicHttpBinding"
       bindingConfiguration="CustomHttpBinding"
       contract="WCF_Service.ICubeService"
       
       name="CubeServiceEndpoint"
       behaviorConfiguration="SilverlightFaultBehavior"/>
    
     <endpoint address="mex" binding="mexHttpBinding" name="MetadataEndpoint"
      contract="IMetadataExchange" />
     </service>
     </services>
     <serviceHostingEnvironment multipleSiteBindingsEnabled="true" >
     
     <serviceActivations>
     <add relativeAddress="CubeService.svc" service="WCF_Service.CubeService" factory="CubeHostFactory"/>
     </serviceActivations>
     </serviceHostingEnvironment>
     </system.serviceModel>
     <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
    
     </system.webServer>
    </configuration>
    

     

    As you can see I have commented the authorization section since it gave me a HTTP Error 500.19 with the error code 0x8007003. (Configuration section 'authorization' cannot be read because it is missing a section declaration.)

    But without it I get Error message 401.3: You do not have permission to view this directory or page using the credentials you supplied (access denied due to Access Control Lists).

    Im fairly sure there is something wrong with my web.config. I haven't found anything that helped by using google either so I'm kind of lost at the moment.

     



    • Edited by faaeen Monday, May 16, 2011 7:11 PM typo
    Monday, May 16, 2011 7:06 PM

Answers

  • Hello, please make sure the compiled assembly is copied to the bin folder under the web site. Also, you need to write both namespace and class name in the Factory attribute. So your second version "IISHost.CubeHostFactory" is correct, while the first version "CubeHostFactory" is incorrect.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by faaeen Wednesday, May 18, 2011 4:13 PM
    Wednesday, May 18, 2011 1:51 AM

All replies

  • From the error message you are getting it sounds like there's a problem accessing the .svc file.  I would check the AppPool your service is running under and make sure the Identity has access to the .svc file for your service. 

    Thanks,

    Michael Green
    WCF Documentation Team

    Monday, May 16, 2011 10:21 PM
  • From the error message you are getting it sounds like there's a problem accessing the .svc file.  I would check the AppPool your service is running under and make sure the Identity has access to the .svc file for your service. 

    Thanks,

    Michael Green
    WCF Documentation Team

    Thanks for your reply Michael.

    The AppPool I'm currently using for the service is using the ApplicationPoolIdentity.

    Additionally, I gave the AppPool complete rights to the folder, in which the project is, via the security tab in the Windows Explorer.

    But I'm still getting the 401.3 error message - You do not have permission to view this directory or page using the credentials you supplied (access denied due to Access Control Lists). 

    This might not be related to the problem, but the project folder is marked with the "Read-only" attribute. Although this seems to be the case for all my folders and not possible to change.

     

     

    Edit: I've now tried publishing the service on a new IIS Site. It seems that I'm no longer getting any permission related errors at least!

    Instead: 

    Server Error in '/' Application.
    
    The type 'CubeHostFactory', provided as the Factory attribute value in the 'system.serviceModel/serviceHostingEnvironment/serviceActivations' section in configuration file could not be found.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidOperationException: The type 'CubeHostFactory', provided as the Factory attribute value in the 'system.serviceModel/serviceHostingEnvironment/serviceActivations' section in configuration file could not be found.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    

     

     

    I haven't published a service this way before so please bear with me. 

    Right now I'm referring to the CubeHostFactory (my own implementation of ServiceHostFactory) in both the web.config and .svc file.

    Web.config :

    <serviceActivations>
      <add relativeAddress="CubeService.svc" service="WCF_Service.CubeService" factory="CubeHostFactory"/>
      </serviceActivations>
    

     

    .Svc:

    <%@ ServiceHost Language="C#" Debug="true" Service="WCF_Service.CubeService" Factory="IISHost.CubeHostFactory" %>
    

     

    This leaves me with a few questions:

     Is this a correct way to hook a ServiceHostFactory to my service?

     Do I need the .svc file or is the web.config enough in this case?

     

     

     


    • Edited by faaeen Tuesday, May 17, 2011 6:02 PM Clarification
    Tuesday, May 17, 2011 5:03 PM
  • Hello, please make sure the compiled assembly is copied to the bin folder under the web site. Also, you need to write both namespace and class name in the Factory attribute. So your second version "IISHost.CubeHostFactory" is correct, while the first version "CubeHostFactory" is incorrect.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by faaeen Wednesday, May 18, 2011 4:13 PM
    Wednesday, May 18, 2011 1:51 AM
  • It seems to be working now.

    Thanks a lot for taking your time to help me, Michael and Yi-Lun.

     

    Wednesday, May 18, 2011 4:15 PM