问题
Is it possible to have communication between uwp and non uwp apps. My non-uwp is a background task which provides a service. I want to call that non-uwp service in uwp app.
How to make that call? Is AppServiceConnection class available in non-uwp app?
回答1:
Yes, non-UWP apps can use AppServices to communicate with UWP apps.
There is a sample here: https://github.com/Microsoft/DesktopBridgeToUWP-Samples/blob/master/Samples/AppServiceBridgeSample_C%2B%2B/cs/Win32Process_CPP/Win32Process_CPP.cpp
回答2:
i think i have the answer for you.
First off, if you want typical win32 functionality that is as easy to design as UWP, you should go for WPF, it pretty much uses the same designing framework but it can support all the things that UWP doesnt, traditional things like a Wndproc loop and sending messages to other applications can be supported on WPF.
Now, the way to get cross app communication on UWP, is by substructing the U from its name, it will stop being universal if you wish to go on with it.
Before i get deeper on why this is, i should explain how this whole Appservice thing works.
Appservice is a background service that can be called from other applications, its hosted under Backgroundhost.exe so this ensures it runs on a different thread than the app, thus preserving the sandbox, as i said it can be started by another app, its much like a class/method in your program that can be fired up by something outside, you can still change appfolder settings with them so you let your main app know what happened in this communication.
So in order for other apps, to access this app service they have to know the address of it, and in order to know that, you gotta hardcode it your self and include it on your folder as well as firing it up through your main APP, and this is only allowed on the desktop versions of UWP, so you see, in any case its better to use WPF.
And if the windows shop is the reason why you want to go with UWP then check out the guide on how to migrate a traditional dekstop app to the windows shop. https://docs.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-root
Furthermore if you are interested on the shiny new apis like the compact overlay that are only supported on UWP, you shouldnt, because there some ways to get it to work on normal desktop apps too.
回答3:
A simple way is to create Windows service (but read about their limitations) with WCF services or other RPC framework (I used WAMP Sharp) and call it from UWP app or from Win32 app. I assume it isn't the best practice, but for our case, it worked like a charm. Also, don't forget to turn on loopback for UWP app.
回答4:
One way for a UWP app to communicate with desktop app would be to use named pipes. But since a UWP app cannot directly communicate over named pipes you can use brokered component to achieve this. You can get more details on how to create brokered component here : https://docs.microsoft.com/en-us/windows/uwp/winrt-components/brokered-windows-runtime-components-for-side-loaded-windows-store-apps
来源:https://stackoverflow.com/questions/43182643/communication-between-uwp-and-non-uwp-app