[英]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: 特征:
Solution: 解:
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.