简体   繁体   English

自定义ServiceHostFactory在Windows Server 2012和IIS 8.5上失败

[英]Custom ServiceHostFactory fails on Windows Server 2012 and IIS 8.5

I am experiencing a very weird error with a WCF service on a Windows 2012 Server R2 Standard with IIS Version 8.5.9600.16384. 我在使用IIS版本8.5.9600.16384的Windows 2012 Server R2 Standard上遇到WCF服务时遇到了一个非常奇怪的错误。 I have implemented a Custom ServiceHostFactory as you can see in the code below. 我已经实现了一个Custom ServiceHostFactory,如下面的代码所示。 I used Visual Studio 2013 Update 4 to compile the code and publish it on my local machine. 我使用Visual Studio 2013 Update 4编译代码并将其发布到我的本地计算机上。 The service works fine locally. 该服务在当地工作正常。 But when I try to deploy the same code (just copy all the files from my machine to the server) I get an HttpCompileException exception. 但是当我尝试部署相同的代码(只是将我的机器中的所有文件复制到服务器)时,我得到一个HttpCompileException异常。 The Application Pool is setup with .NET Version v4.0.30319 and the Managed pipeline mode is “Integrated” in both machines, mine and the server. 应用程序池使用.NET V4.0.30319进行设置,托管管道模式在机器,我的和服务器中都是“集成”。 I cannot understand why the same code works on my machine and not on the server. 我无法理解为什么相同的代码在我的机器上工作而不在服务器上。 The only difference between the two is the operating system and IIS version. 两者之间的唯一区别是操作系统和IIS版本。 My machine runs Windows 7 and IIS 7. 我的机器运行Windows 7和IIS 7。

MyService.svc contains the following: MyService.svc包含以下内容:

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

Here is my implementation of CustomServiceHostFactory that extends UnityServiceHostFactory. 这是我的CustomServiceHostFactory实现,它扩展了UnityServiceHostFactory。

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

Here is my implementation of UnityServiceHostFactory that extends System.ServiceMode.Activation.ServiceHostFactory 这是我扩展System.ServiceMode.Activation.ServiceHostFactory的UnityServiceHostFactory实现

public class UnityServiceHostFactory : ServiceHostFactory
   {
       private readonly IUnityContainer _container;

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

Here is the 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's \\App_Code directory, contained in a compiled assembly located in the application's \\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's 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's \\App_Code directory, contained in a compiled assembly located in the application's \\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's root directory and cannot be nested in subdirectories.

I would be very grateful if someone could help me with this issue. 如果有人可以帮我解决这个问题,我将非常感激。

Thanks in advance. 提前致谢。

Edit: 编辑:

Below you will find a list of the .NET versions and tools I have installed on my Windows Server 2012. My project is compiled with .NET Framework 4.5. 下面是我在Windows Server 2012上安装的.NET版本和工具的列表。我的项目是使用.NET Framework 4.5编译的。

Features: 特征:

  • NET Framework 3.5 Features NET Framework 3.5功能
  • Net Framework 3.5 (includes .NET 2.0 and 3.0) Net Framework 3.5(包括.NET 2.0和3.0)
  • HTTP Activation HTTP激活
  • NET Framework 4.5 Featues .NET Framework 4.5特性
  • .Net Framework 4.5 ASP.NET 4.5 .Net Framework 4.5 ASP.NET 4.5
  • WCF Services WCF服务
  • HTTP Activation HTTP激活
  • Name Pipe Actication 名称管道行为
  • TCP Actication TCP行动
    -TCP Port Sharing -TCP端口共享

Solution: 解:

  • Add a reference to Microsoft.Practices.Unity.dll in your project. 在项目中添加对Microsoft.Practices.Unity.dll的引用。

My project was missing a reference to Microsoft.Practices.Unity.dll. 我的项目缺少对Microsoft.Practices.Unity.dll的引用。 My local machine must have that dll file somewhere else so that the service worked fine locally. 我的本地机器必须在其他地方有该DLL文件,以便本地服务工作正常。 However the server did not have it. 但是服务器没有它。 So it reacted by giving me a very unhelpful message to tell me I was missing a reference. 所以它的反应是给我一个非常无益的信息,告诉我我错过了一个参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法阻止Windows Server 2012上的IIS 8.5中的回收 - Cannot prevent recycling in IIS 8.5 on windows server 2012 应用程序在Server 2012和IIS 8.5上意外重新启动 - Application restarted unexpectedly on Server 2012 and IIS 8.5 405 - 不允许用于访问此页面的 HTTP 动词。 [IIS 8.5] [Windows Server 2012 R2] - 405 - HTTP verb used to access this page is not allowed. [IIS 8.5] [Windows Server 2012 R2] 在Windows 2012服务器IIS 8.0中进行IIS调试 - IIS debugging in windows 2012 server IIS 8.0 Windows 7上构建的二进制文件在Windows Server 2012上失败 - Binaries built on Windows 7 fails on Windows Server 2012 IIS 8.5 / Windows 2012 R2应用程序池HTML渲染破坏了Javascript - IIS 8.5/Windows 2012 R2 Application Pool HTML Rendering Is Breaking Javascript 在Windows Server 2012上将IIS连接到SQL Server 2014 - Connecting IIS to SQL Server 2014 on Windows Server 2012 基本NLog文件目标在IIS 8和Windows Server 2012下不起作用 - Basic NLog file target not working under IIS 8 and Windows Server 2012 创建代理实例失败,出现COMException(IIS,Windows Server 2012,NHibernate) - Creating a proxy instance failed with COMException (IIS, Windows Server 2012, NHibernate) Windows Server 2012内存限制上的IIS工作进程 - IIS Worker Process on Windows Server 2012 Memory Limit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM