question

baget avatar image
1 Vote"
baget asked ·

How UWP can communicate with Windows Service

Hi

I have Windows Service (C++ win32) and UI application (C#), today they communicate via COM Object.
I would like to convert the UI to UWP, what are my options for IPC Between the Service and the UWP app?
I still need the Service to stay Win32 Windows Service.

windows-uwpwindows-uwp-runtime
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

baget avatar image
2 Votes"
baget answered ·

it seems like the right approach is using a CustomCapability
here is a sample code


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered ·

Hello,​

Welcome to our Microsoft Q&A platform!

UWP could not communicate with Windows Service directly. In order to implement the IPC between windows service and UWP apps, a possible way is to create a win32 app that could communicate with the Windows Service, and then the UWP app could communicate with the win32 app using App Service.

With the capability-runFullTrust, UWP apps could launch the win32.exe file. It is a restricted capability which means you must provide info during the app submission process in order to be approved to publish the app to the Microsoft Store. Sideload apps don't need to receive any approval to use the restricted capability. For more information about restricted capabilities, please refer to Restricted capabilities.

Here is a sample about how UWP apps could launch the win32 exe file and communicate with it using App Service: AppService Bridge Sample

Please note if you want to use App Service APIs in win32 apps, you will need to add some references first. For more information, please refer to Call UWP APIs in desktop apps.


· 4 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I found this
CustomCapability sample

isn't that better solution? or should I stick to App Service?


1 Vote 1 ·

Yes, that might be a possible way to do that. It depends on your requirement that decides which way to achieve the goal.

1 Vote 1 ·

@baget I suggest answering your own question with that link and accepting it if it proved useful to you. I initially missed your comment when scanning the topic, but I believe that yours is the answer people will want to find. It was certainly the answer I was looking for.

1 Vote 1 ·

Thank you this was very helpfull.

0 Votes 0 ·
Ivanich avatar image
0 Votes"
Ivanich answered ·

In theory, you can try reinvent a bicycle and use Windows objects for communication. For example, named mutex and named memory mapped file should be enought to build interprocess communication.

· 4 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

For whom it may concern:

I made a library for IPC between UWP app and .Net Framework Windows Services through shared memory, it does not require any special capabilities.

GitHub repository

Nuget package


1 Vote 1 ·

Nice, does it support C++? or just .NET?

0 Votes 0 ·

Good point! For now it is .Net Framework 4.6 library on Win32 side and .Net Standard on UWP side, but in theory it should be possible to compile this library as Windows Runtime Componenent and use from C++ UWP app. I'll try to do it on weekend.

More important thing is that memory mapped files can be shared between Win32 and WinRT simply by adding the application's SID to the access list when Win32 process creates them, so any library for memory mapped files that supports access control lists should work.

1 Vote 1 ·

Just made Nuget package with WinRT adapters: https://www.nuget.org/packages/CorpusCallosum.WinRT/

1 Vote 1 ·