繁体   English   中英

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

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

我在使用IIS版本8.5.9600.16384的Windows 2012 Server R2 Standard上遇到WCF服务时遇到了一个非常奇怪的错误。 我已经实现了一个Custom ServiceHostFactory,如下面的代码所示。 我使用Visual Studio 2013 Update 4编译代码并将其发布到我的本地计算机上。 该服务在当地工作正常。 但是当我尝试部署相同的代码(只是将我的机器中的所有文件复制到服务器)时,我得到一个HttpCompileException异常。 应用程序池使用.NET V4.0.30319进行设置,托管管道模式在机器,我的和服务器中都是“集成”。 我无法理解为什么相同的代码在我的机器上工作而不在服务器上。 两者之间的唯一区别是操作系统和IIS版本。 我的机器运行Windows 7和IIS 7。

MyService.svc包含以下内容:

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

这是我的CustomServiceHostFactory实现,它扩展了UnityServiceHostFactory。

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

这是我扩展System.ServiceMode.Activation.ServiceHostFactory的UnityServiceHostFactory实现

public class UnityServiceHostFactory : ServiceHostFactory
   {
       private readonly IUnityContainer _container;

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

这是一个例外:

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.

如果有人可以帮我解决这个问题,我将非常感激。

提前致谢。

编辑:

下面是我在Windows Server 2012上安装的.NET版本和工具的列表。我的项目是使用.NET Framework 4.5编译的。

特征:

  • NET Framework 3.5功能
  • Net Framework 3.5(包括.NET 2.0和3.0)
  • HTTP激活
  • .NET Framework 4.5特性
  • .Net Framework 4.5 ASP.NET 4.5
  • WCF服务
  • HTTP激活
  • 名称管道行为
  • TCP行动
    -TCP端口共享

解:

  • 在项目中添加对Microsoft.Practices.Unity.dll的引用。

我的项目缺少对Microsoft.Practices.Unity.dll的引用。 我的本地机器必须在其他地方有该DLL文件,以便本地服务工作正常。 但是服务器没有它。 所以它的反应是给我一个非常无益的信息,告诉我我错过了一个参考。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM