2015-04-22 102 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文件,以便該服務在本地正常工作。但是服務器沒有它。所以它給了我一個非常無益的信息,告訴我我錯過了一個參考。

相關問題