【发布时间】:2020-10-22 19:09:09
【问题描述】:
我有一个在 Server 2012R2 上运行的 WCF 服务。我尝试将服务移至 Server 2016 并开始收到以下错误:
找不到类型“MyService”,在 ServiceHost 指令中作为 Service 属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。
我确实将整个目录从一台服务器移动到另一台服务器——所以所有代码和设置都是相同的。
我的服务在web.config 中配置如下:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
...
<services>
<service name="MyService" behaviorConfiguration="BehaviorConfig">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="json" contract="IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
我的myservice.svc 看起来像这样:
<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
是的,包含该服务的 .dll 位于我的 Bin 目录中。
我的服务定义如下所示:
[ServiceContract(Namespace="")]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method ="POST", RequestFormat=WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
string Validate(string userId, string userText);
[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
void UserName(string userId);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService: BaseService, IMyService
{
//Implementation here
}
所以我阅读了一些帖子,表明.svc 文件应该包含服务的类型——包括命名空间。但是,就我而言,没有命名空间。
该项目针对 .NET Framework 4.6.1。
我错过了什么?
【问题讨论】:
-
您是否阅读过这个问题,尤其是已接受答案中的链接:stackoverflow.com/q/720807/5311735?第一个链接表明这可能是依赖库的问题(可能在原始服务器上的 GAC 中,而不是在您复制的目录中)
-
刚刚使用 Dependencies 应用程序来检查 dll。它似乎可以毫无问题地找到所有依赖项。
-
您可以尝试在第一个链接 (thejoyofcode.com/…) 中使用的调试方法 - 即尝试通过 Activator.CreateInstance 从 aspx 页面创建您的类型,看看是否会显示更多信息。
-
我认为你需要以管理员身份运行它
标签: c# wcf windows-server-2012-r2 windows-server-2016