Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use WCF services in Windows 10 Universal App?

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?

like image 457
ebattulga Avatar asked Aug 06 '15 00:08

ebattulga


People also ask

How do I run a WCF service?

Press Ctrl + F5 to run the service. Open WCF Test Client. To open WCF Test Client, open Developer Command Prompt for Visual Studio and execute WcfTestClient.exe. Select Add Service from the File menu.

What is WCF services in Windows 10?

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

What is the difference between WCF and Windows service?

A windows service is what you need. WCF is a communications library, and unless you plan to communicate with your application via a client, you don't need it. Your problem is related to activation, and keeping your code active in the background is what windows services do.


2 Answers

Thank you for @gregkalapos

1. Create Windows 8.1 Portable class library enter image description here

2. Choose like this

enter image description here

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

enter image description here

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

like image 61
ebattulga Avatar answered Nov 15 '22 12:11

ebattulga


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...

like image 35
gregkalapos Avatar answered Nov 15 '22 13:11

gregkalapos