[英]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編譯的。
特征:
解:
我的項目缺少對Microsoft.Practices.Unity.dll的引用。 我的本地機器必須在其他地方有該DLL文件,以便本地服務工作正常。 但是服務器沒有它。 所以它的反應是給我一個非常無益的信息,告訴我我錯過了一個參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.