How to use WCF services in Windows 10 Universal App?

廉价感情. 提交于 2019-12-18 12:30:31

问题


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?


回答1:


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




回答2:


I also have this problem. The workaround I used was that I created a Portable Class Library targeting only Windows Runtime and added the service reference into that and I referenced the PLC in the UWP app. Btw. I think this is a known bug...



来源:https://stackoverflow.com/questions/31844768/how-to-use-wcf-services-in-windows-10-universal-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!