.NET Core中的WCF参考文档

7
我该如何将WCF引用到我的.NET Core客户端?我下载并安装了"WCF Service Preview"插件,但在尝试添加引用时出现错误。
错误:未找到与.NET Core应用程序兼容的终结点。工具中发生了错误。
无法生成服务引用。

enter image description here

当我在浏览器中尝试服务时,一切正常。有什么想法吗? 我的WCF Web配置文件:
<?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>

微软已将所有重点转向用于.NET Core的Visual Studio 2017 RC。你应该尝试通过它生成引用,而不是在被放弃的VS2015中工作。 - Lex Li
您可以在此处找到解决方案: https://dev59.com/RFkT5IYBdhLWcg3wELkl#39895385 - Ruthi
你是想在 .net core 中托管一个 WCF 服务吗?还是尝试从 .net core 代码中使用 WCF 服务? - tom redfern
2个回答

4

取消选中 在引用的程序集中重复使用类型


1
我几天前遇到了类似的问题,但无法找到特定原因,导致扩展程序无法正确识别端点。我通过创建一个包含实际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 - Timothy Truckle
1
@TimothyTruckle,您的评论与用户的答案之间似乎没有明显的关系(甚至不是一个问题!)。这只是复制/粘贴错误吗?尽管如此,感谢您的礼貌和显然的帮助尝试... :) - pbristow
这个答案真的救了我的一天,经过数小时的疑难解答,最终代理类库(.net framework)拯救了我,因为我无法将旧的WCF服务(编写在.net framework 4.0中)引用到.net core 2.1 web API应用程序中。非常感谢你。虽然你的回答已经四年了,但现在我可以说,你可以安全地忽略我上面那些愚蠢的评论。 - Chestera
很高兴这个答案有帮助!在工具无法生成.NET Core中的服务引用的情况下,这里的答案是正确的,可能是由于一些结构问题,我无法确定实际原因。最终唯一的解决方案是编写在GitHub项目中演示的自定义方法。 - Jolmari

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接