1

I have an Enterprise LOB scenario, where I need to communicate between my Sideloaded UWP app and multiple console applications which are developed by third parties. Internally, these console apps will be interfacing with COM ports and hardware devices.

Can I use App Service to communicate between UWP and out-of-package Console App?

Further more, the communication must be two way and asynchronous, expected flow:

  1. UWP -start-console-app-expect-no-response-> Console App (How to achieve this step without desktop-bridge?)
  2. UWP <-send-data-expect-no-response- Console App
  3. UWP -send-data-expect-no-response-> Console App

I have already referred the links below but according to them "Windows Application Packaging Project" is a must.

Please do suggest if there are any other alternatives too.

EDIT:

It is possible to start out-of-package Console Apps from UWP using 2 methods:

  1. Create a package with a Console App which can launch any other Console app(s). Refer: https://stackoverflow.com/a/49340814/10224384
  2. Launch Console App via protocol URI. Create a URI protocol to Console App: https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914%28v%3dvs.85%29 OR https://www.meziantou.net/registering-an-application-to-a-uri-scheme-using-net.htm

However, it is not possible to communicate between the out-of-package Console App and the UWP via the App Service. Even though, the Console app has reference to Microsoft.Windows.SDK.Contracts nuget package and can access AppServiceConnection API since AppServiceConnection class has the DualApiPartitionAttribute. The connection cannot be established with the AppServiceUnavailable Error.

Hence, Now I'm trying a new solution with option 1 from above as mentioned here: https://learn.microsoft.com/answers/questions/1166/how-uwp-can-communicate-with-windows-service.html?childToView=1211#answer-1211

Fallback options that need investigation:

  • WCF Http/NamedPipes
  • UWP starts Console App, Console App responds by invoking a Launch by URI protocol (Of course the UWP needs to register the Protocol)
Nabster
  • 1,187
  • 2
  • 10
  • 27
  • 1
    Hi, UWP is a sandbox application, and its operating environment is relatively independent. If you need to communicate with a win32 console program, you must include it in a package to build a full trust program. – Richard Zhang Feb 13 '20 at 00:36
  • What about in case my Console app has reference to Microsoft.Windows.SDK.Contracts nuget package and can access AppServiceConnection API since AppServiceConnection class has the DualApiPartitionAttribute? In which case it might almost be acting as a UWP right? and in principal we can communicate between UWPs right? – Nabster Feb 13 '20 at 01:51

2 Answers2

0

AppServiceConnection cannot be used to establish communication between out-of-package Console App and UWP, see the updated question.


From comments, I think this can be achievable, but it should not be through the COM port, but to establish AppServiceConnection.

Please refer to this document to create AppService for UWP applications. If your console app can create an AppServiceConnection, then you can establish a connection with the UWP app and transfer data.

AppServiceConnection is a two-way communication. After the connection is established, the console app and UWP app can send information to each other.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Richard Zhang
  • 7,523
  • 1
  • 7
  • 13
  • The COM port comms was only from the Console App so I have removed the COM port communication for the sake of simplicity of the question. Now as the first step goes, How can I launch the console app from the UWP without a "desktop bridge"? – Nabster Feb 13 '20 at 02:50
  • 1
    Do you want to launch a console application using a UWP application? This may not work. I refer to ·AppService· as a method for establishing communication between the two parties after the applications are started. UWP launching other applications can be carried out through the application protocol and Uri, but cannot launch external applications (such as `Process`) **(this is untrusted)**. – Richard Zhang Feb 13 '20 at 03:01
  • Well, there could be a workaround using "protocol launching".. It is possible to Launch URI from UWP. In principle, if the protocol is registered to a console app then the console app may start when launching the URI. It may be implied here: https://stackoverflow.com/a/48776297/10224384 – Nabster Feb 13 '20 at 03:43
  • 1
    Yes, this is possible if you can create an application protocol for the Console App. In UWP, you can set the application protocol in `package.appxmanifest`, but it may be more complicated for the Console App. You can search some relevant information to help you register for the application protocol. – Richard Zhang Feb 13 '20 at 04:21
  • Yes, in case of Console Apps it is required to make registry entries, etc.. Anyway, now to avoid these many workarounds, I'm investigating WCF for the communication. – Nabster Feb 13 '20 at 05:12
  • Any method is encouraged. If you have a good solution, you can post an answer, it will help more people. – Richard Zhang Feb 13 '20 at 05:41
0

I finally completed with many workarounds involved, I'm still looking for better solutions though. My LOB scenario is kind of a special case(refer question) and works fine for me but for others I dont recommend this solution.

Constraints with the solution:

  • Application needs to be sideloaded since it uses a restricted responsibility (runFullTrust)
  • For the 3rd Party exe to use Launcher.LaunchUriAsync, it needs to import the Microsoft.Windows.SDK.Contracts nuget package (Refer this and this)
  • Communication, rather app-to-app Initiation is of course only one way:
    • UWP just triggers a start and passes parameters
    • Console apps too can only start the UWP using Protocol URIs
  • 3rd party .exe Name and Directory must be known before hand
    • As a workaround, the .exe could also be launched using Protocol but that requires the .exe to make Registry Entry
  • Handle timeout and failure scenarios by self

UWP - out-of-package exe communication

Nabster
  • 1,187
  • 2
  • 10
  • 27