首页 > 解决方案 > 如何使用 .net core 3.0 中开发的 wpf 中的 wcf

问题描述

我需要使用在 .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 服务的指南,请告诉我。

标签: c#wpfwcf.net-core-3.0

解决方案


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

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

使用 WCF Web 服务引用提供程序工具

...

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

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

...

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

推荐阅读