2015-04-22 53 views
3

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

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 
     } 
    } 

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

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上的.NET版本和工具2012年我的项目是使用.NET框架4.5编写的列表。

特点:

  • NET框架3.5特点
  • .Net框架3.5(包括.NET 2.0和3.0)
  • HTTP激活
  • NET框架4.5 Featues
  • 。 Net Framework 4.5 ASP.NET 4.5
  • WCF服务
  • HTTP激活
  • 命名管道ACTICATION
  • TCP ACTICATION
    -TCP端口共享
+1

它似乎是一个.NET框架问题,因为它说CLR类型无法加载,检查你的服务器上有什么.NET版本 – Coder1409

回答

0

解决方案:

  • 添加到Microsoft.Practices.Unity.dll参考在你的项目中。

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

相关问题