【问题标题】:How use wcf from wpf developed in .net core 3.0如何使用 .net core 3.0 中开发的 wpf 中的 wcf
【发布时间】:2019-05-22 09:27:33
【问题描述】:

我需要使用在 .NET Core 3.0 预览版 5 中开发的 WPF 中的 WCF 服务。在 Visual Studio 中,我无法使用 Add -> Service reference,因为 VS 现在不支持此选项。

我的第一个选项是在 .csproj 中写入运行项目所需的所有组件,但它不起作用。

这是我的 .csproj。

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <None Include="Connected Services\ServiceTime\Time.wsdl" />
    <None Include="Connected Services\ServiceTime\Time.xsd">
      <SubType>Designer</SubType>
    </None>
    <None Include="Connected Services\ServiceTime\Time1.xsd">
      <SubType>Designer</SubType>
    </None>
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Connected Services\" />
  </ItemGroup>
  <ItemGroup>
    <WCFMetadataStorage Include="Connected Services\ServiceTime\" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Connected Services\ServiceTime\Time.disco" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Connected Services\ServiceTime\configuration91.svcinfo" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Connected Services\ServiceTime\configuration.svcinfo" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Connected Services\ServiceTime\Reference.svcmap">
      <Generator>WCF Proxy Generator</Generator>
      <LastGenOutput>Reference.cs</LastGenOutput>
    </None>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Windows.Compatibility" Version="2.1.1" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="TimeService">
      <HintPath>..\..\TimeService\TimeService\bin\TimeService.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

TimeService 工作正常。

如果有人知道在 WPF 使用 .NET Core 3.0 中使用 WCF 服务的指南,请告诉我。

【问题讨论】:

  • Wcf 未在网络核心中实现。我从未尝试过,但你不能使用 wcf 并不让我感到惊讶。你现在应该使用 web api 之类的 RESTful 服务。
  • @Andy - 客户端已实现
  • 至于替代方案(服务器端),MS 暗示 gRPC

标签: c# wpf wcf .net-core-3.0


【解决方案1】:

我需要使用 .NET Core 3.0 预览版 5 中开发的 WPF 中的 WCF 服务。在 Visual Studio 中,我无法使用 Add -> Service reference,因为 VS 现在不支持此选项。

对于 .NET Core,您可以将其添加为连接服务。

Use the WCF Web Service Reference Provider Tool

...

WCF Web 服务参考选项适用于使用以下项目模板创建的项目:

  • Visual C# > .NET Core
  • Visual C# > .NET 标准
  • Visual C# > Web > ASP.NET Core Web 应用程序

...

  1. 在解决方案资源管理器中,双击项目的 Connected Services 节点
  2. 在“连接的服务”页面上,单击 Microsoft WCF Web 服务参考提供程序。这将打开配置 WCF Web 服务参考向导:

【讨论】:

  • 这适用于任何 WCF 服务吗?有约束力,有合同吗?还是只是带有 WSDL 的 SOAP 服务?
  • @nvoigt 它至少支持 SOAP、websockets 和 net.tcp github.com/dotnet/wcf/tree/master/src/… 在绑定支持的地方也是双工的。没有 msmq。 dotnet-svcutil 不如 svcutil 成熟,但在大多数情况下,您可以将其争先恐后地做您需要的事情。
【解决方案2】:

我不能使用 Add -> Service reference,因为 VS 现在不支持这个选项。

是的。它在“添加连接的服务”下。

您似乎想添加一个 WCF 客户端,但请务必清楚这一点。 Core 不支持 WCF 服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 2020-04-16
    • 2020-11-20
    • 2022-10-24
    • 1970-01-01
    相关资源
    最近更新 更多