Search code examples
c#uwpconsole-applicationwindows-10-universaldesktop-bridge

Using App Service between Side-loaded UWP and Console App without App packaging project


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)

Solution

  • 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