如何在 Windows 10 通用应用中使用 WCF 服务? [英] How to use WCF services in Windows 10 Universal App?

查看:22
本文介绍了如何在 Windows 10 通用应用中使用 WCF 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 8.1 应用使用 WCF 服务.我需要将我的应用程序移植到 Windows 10 UWP 应用程序.但不能添加服务引用.当我添加服务引用时会出现此消息:

<块引用>

数据服务客户端代码生成失败.不支持指定的 Windows 应用商店框架.NETCore,Version=v5.0".仅支持 .NETCore 4.5 及更高版本.

如何解决我的问题?

解决方案

感谢@gregkalapos

1.创建 Windows 8.1 可移植类库

2.像这样选择

3.将服务引用添加到新创建的库中.然后引用库到 Windows 10 通用应用项目.

这是示例调用方法:

var client = new ConnectODataEntities(new Uri("http://...ODATA URL..."));var dsQuery = (DataServiceQuery)(client.YOUR_METHOD);var tf = new TaskFactory>();var list = (await tf.FromAsync(dsQuery.BeginExecute(null, null),iar =>dsQuery.EndExecute(iar))).ToList();lbox.ItemsSource = 列表;

<块引用>

此方法使用的应用适用于 Windows 10Windows 10 Mobile

My Windows 8.1 app uses WCF services. I need to port my app to Windows 10 UWP app. But cannot add service reference. This message appears when I add a service reference:

Data service client code-generation failed. Specified Windows Store Framework '.NETCore,Version=v5.0' is not supported. Only .NETCore 4.5 and above is supported.

How to solve my problem?

解决方案

Thank you for @gregkalapos

1. Create Windows 8.1 Portable class library

2. Choose like this

3. Add Service Reference to newly created library. Then reference library to Windows 10 Universal App project.

This is example call method:

var client = new ConnectODataEntities(new Uri("http://...ODATA URL..."));
var dsQuery = (DataServiceQuery<YOUR_METHOD_RETURN_TYPE>)(client.YOUR_METHOD);

var tf = new TaskFactory<IEnumerable<YOUR_METHOD_RETURN_TYPE>>();
var list = (await tf.FromAsync(dsQuery.BeginExecute(null, null),
                            iar => dsQuery.EndExecute(iar))).ToList();



lbox.ItemsSource = list;

This method used app works on Windows 10 and Windows 10 Mobile

这篇关于如何在 Windows 10 通用应用中使用 WCF 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆