【问题标题】:WCF reference in .NET Core.NET Core 中的 WCF 参考
【发布时间】:2017-04-25 20:03:00
【问题描述】:

如何将 WCF 引用到我的 .NET Core 客户端?我下载并安装了“WCF 服务预览”插件,但是当我尝试添加参考时出现错误

错误:未找到与 .Net Core 应用程序兼容的端点。 工具出现错误。

未能生成服务参考。

当我在浏览器中尝试服务时,工作正常。有任何想法吗 ? 我的 WCF 的网络配置:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>

  <system.serviceModel>
    <services>
      <service name="ServiceLayer.TeamManagementService" behaviorConfiguration="GetDataBehavior">
        <endpoint address="" binding="webHttpBinding" contract="ServiceLayer.ITeamManagementService" behaviorConfiguration="GetDataEndpointBehavior"></endpoint>
      </service>
    </services>

    <behaviors>

      <serviceBehaviors>
        <behavior name="GetDataBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>

      <endpointBehaviors>
        <behavior name="GetDataEndpointBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>

    </behaviors>

    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
        preCondition="managedHandler"/>
    </modules>
    <directoryBrowse enabled="true"/>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>

</configuration>

【问题讨论】:

  • Microsoft 已将所有重点转移到 Visual Studio 2017 RC for .NET Core。您应该尝试通过它来生成引用,而不是在已废弃的 VS2015 中工作。
  • 您可以在这里找到解决方案:stackoverflow.com/a/39895385/1520221
  • 您是否尝试在 .net 核心的 WCF 中托管服务?或者您是否尝试从 .net 核心代码中使用 WCF 服务?

标签: c# asp.net .net wcf .net-core


【解决方案1】:

取消选中Reuse types in referenced assemblies

【讨论】:

    【解决方案2】:

    几天前我遇到了类似的问题,但找不到扩展无法正确识别端点的具体原因。我通过创建一个包含实际 WCF 服务代理的类库项目解决了这个问题。 NET Core 项目然后可以引用此项目并在没有连接引用的情况下间接调用服务。

    如果您还没有找到问题的解决方案,请查看我的 github 存储库以查看示例: https://github.com/jolmari/netcore-wcf-service-proxy

    【讨论】:

    • 欢迎来到 Stack Overflow!请使用tour,环顾四周,并通读help center,尤其是How do I ask a good question?What topics can I ask about here?。从第二个链接:“要求家庭作业帮助的问题必须包括您迄今为止为解决问题所做的工作的摘要,以及您在解决问题时遇到的困难的描述。” - 请在此处发布mcve
    • @TimothyTruckle 您的评论与用户回答之间没有明显的关系(甚至不是问题!)。这只是复制/粘贴错误吗? +1 为了您的礼貌和明显的帮助,不过...... :)
    • 这个答案实际上拯救了我的一天,经过数小时的故障排除终于代理类库(网络框架)救了我,因为我无法将旧的 wcf 服务(用网络框架 4.0 编写)引用到网络核心2.1 wep API 应用程序。非常感谢你。你的回答已经过去了 4 年,但我现在可以说你可以放心地忽略我上面的这个愚蠢的 cmets
    • 我很高兴这个答案很有帮助!在由于某些结构问题而导致工具无法在 .NET Core 中生成服务引用的情况下,这里的答案是正确的,我无法弄清楚实际原因是什么。最后唯一的解决方案是编写 GitHub 项目中演示的自定义方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 2021-05-25
    • 1970-01-01
    • 2017-09-18
    • 2017-04-19
    • 2018-01-19
    • 2020-05-14
    相关资源
    最近更新 更多