我在一个安装有IIS Version 8.5.9600.16384的Windows 2012 Server R2 Standard上,使用一个自定义的ServiceHostFactory实现WCF服务时遇到了一个非常奇怪的错误。我使用Visual Studio 2013 Update 4编译代码并将其发布到本地机器上,服务在本地运行正常。但是当我尝试部署相同的代码(只需从我的计算机复制所有文件到服务器)时,会出现HttpCompileException异常。在我的机器和服务器上,应用程序池都设置了.NET版本v4.0.30319,并且托管管道模式均为“集成”。我无法理解为什么相同的代码在我的机器上运行良好,而在服务器上却不行。两者之间唯一的区别是操作系统和IIS版本。我的机器运行Windows 7和IIS 7。
MyService.svc包含以下内容:
这是我实现的CustomServiceHostFactory,它扩展了UnityServiceHostFactory。
这是我对UnityServiceHostFactory的实现,它扩展了System.ServiceMode.Activation.ServiceHostFactory。
<%@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 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 端口共享