c# - 如何使用 .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 服务的指南,请告诉我。
解决方案
我需要使用在 .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 应用程序
...
推荐阅读
- web-scraping - 我正在尝试使用 scrapy 抓取网站,但网站结构不一致
- javascript - 引用 socket.io 时的错误
- c# - WebBrowser 控件中 Template 标记的 InnerHtml 返回 null
- c++ - 有条件地选择带有 decltype() 和三元运算符的类型
- php - 如何在 Visual Studio Code 中将 PHP 项目与 HTML 项目集成?
- mysql - Java Application/Flutter Mobile App 和 MySQL 之间的中间件
- sql - 我想向我的表添加一个约束,但一直显示错误
- mysql - MySQL - 在一个视图中列出所有用户和授权
- reactjs - 将值从组件传递到 redux 存储
- python - ValueError: int() 以 10 为底的无效文字:'–20'