如何使用.net core 3.0开发的wpf中的wcf

How use wcf from wpf developed in .net core 3.0

我需要使用在 .NET Core 3.0 预览版 5 中开发的 WPF 中的 WCF 服务。在 Visual Studio 中,我无法使用添加 -> 服务引用,因为 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 服务的指南,请告诉我。

I cannot use Add -> Service reference because VS doesn't support this option now.

是的。它在 "Add Connected Services" 下。

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

I need to use a WCF service from WPF developed in .NET Core 3.0 preview 5. In Visual Studio I cannot use Add -> Service reference because VS doesn't support this option now.

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

Use the WCF Web Service Reference Provider Tool

...

The WCF Web Service Reference option is applicable to projects created using the following project templates:

  • Visual C# > .NET Core
  • Visual C# > .NET Standard
  • Visual C# > Web > ASP.NET Core Web Application

...

  1. In Solution Explorer, double-click the Connected Services node of the project
  2. On the Connected Services page, click Microsoft WCF Web Service Reference Provider. This brings up the Configure WCF Web Service Reference wizard: