【问题标题】:WCF Service works on Server 2012 R2 but throws error on 2016WCF 服务在 Server 2012 R2 上工作,但在 2016 年抛出错误
【发布时间】: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


【解决方案1】:

我在windows server 2012 R2上发布了WCF服务,文件目录如下:

bin目录下的文件:

然后我把整个目录复制到windows server 2016,就可以成功运行了。

我在这个过程中没有遇到任何问题,你可以参考我复制到windows server 2016的文件。你需要检查你的目录中是否缺少某些文件。如果还是不行,我建议你在部署之前在 2016 年重新构建项目。

【讨论】:

    【解决方案2】:

    我终于得到了这个工作。在搞砸了几个小时之后,我终于意识到,在原来的服务器上,我的 Services 子文件夹也被做成了自己的 Web 应用程序。 IOW,我在 Web 应用程序中有一个 Web 应用程序。

    在新服务器上,我没有将 services 子文件夹变成 Web 应用程序。

    【讨论】:

      猜你喜欢
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      相关资源
      最近更新 更多