Custom ServiceHostFactory doesn't work on Windows Server 2012 and IIS 8.5

I am experiencing a very strange error using WCF service in Windows 2012 Server R2 standard with IIS version 8.5.9600.16384. I have implemented a Custom ServiceHostFactory as you can see in the code below. I used Visual Studio 2013 Update 4 to compile the code and publish it to my local machine. The service works fine on site. But when I try to deploy the same code (just copy all files from my machine to the server), I get an HttpCompileException. The application pool is configured with .NET Version v4.0.30319, and the managed server mode is "Integrated" on both my machines and the server. I don't understand why the same code works on my computer and not on the server. The only difference between the two is the operating system and the IIS version. My machine is running Windows 7 and IIS 7.

MyService.svc contains the following:

<%@ServiceHost
    Language="C#"
    Debug="false"
    Service="MyService"
    Factory="CustomServiceHostFactory"%>

      

Here is my CustomServiceHostFactory implementation that extends UnityServiceHostFactory.

public class CustomServiceHostFactory : UnityServiceHostFactory
  {
      protected override void InitializeLocalDependencies(IUnityContainer container)
      {
          var initializer = new ContainerInitializer();
          initializer.Initialize(container);
      //do stuff
      }
  }

      

Here is my UnityServiceHostFactory implementation that extends System.ServiceMode.Activation.ServiceHostFactory

public class UnityServiceHostFactory : ServiceHostFactory
   {
       private readonly IUnityContainer _container;

       public UnityServiceHostFactory()
       {
           _container = new UnityContainer(); 
          //do stuff    
       }

      

Here's an exception:

Exception information: 
    Exception type: HttpCompileException 
    Exception message: The CLR Type 'CustomServiceHostFactory' could not be loaded during service compilation. Verify that this type is either defined in a source file located in the application \\App_Code directory, contained in a compiled assembly located in the application \\bin directory, or present in an assembly installed in the Global Assembly Cache. Note that the type name is case-sensitive and that the directories such as \\App_Code and \\bin must be located in the application root directory and cannot be nested in subdirectories.
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
   at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)
The CLR Type ‘CustomServiceHostFactory' could not be loaded during service compilation. Verify that this type is either defined in a source file located in the application \\App_Code directory, contained in a compiled assembly located in the application \\bin directory, or present in an assembly installed in the Global Assembly Cache. Note that the type name is case-sensitive and that the directories such as \\App_Code and \\bin must be located in the application root directory and cannot be nested in subdirectories.

      

I would really appreciate if someone can help me on this issue.

Thanks in advance.

Edit:

Below you will find a list of .NET versions and tools that I have installed on my Windows Server 2012. My project is compiled with .NET Framework 4.5.

Features:

  • .NET Framework 3.5 Features
  • Net Framework 3.5 (includes .NET 2.0 and 3.0)
  • HTTP activation
  • NET Framework 4.5 Featues
  • .Net Framework 4.5 ASP.NET 4.5
  • WCF services
  • HTTP activation
  • Name Action pipe
  • TCP-TCP
    Port Sharing Action
+3


source to share


1 answer


Decision:

  • Add a reference to the Microsoft.Practices.Unity.dll file in your project.


My project was missing a reference to Microsoft.Practices.Unity.dll. My local machine must have this DLL file somewhere else for the service to work fine locally. However, this was not the case on the server. So he reacted by giving me a very unhelpful message to tell me I was missing a link.

0


source







All Articles