UWP 应用程序与 Windows 服务的通信 [英] UWP App Communication with Windows Service

查看:45
本文介绍了UWP 应用程序与 Windows 服务的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在修复重新构建应用程序的问题,并且正在讨论是否可以使用 UWP 代替普通的 WPF 应用程序.

We are fixing to re-architect an application and are debating whether or not it is possible to use UWP instead of an ordinary WPF application.

我们的应用程序需要能够访问整个文件系统和所有系统资源.这是一个问题,因为 UWP 应用是沙盒化的.但是,我们正试图通过以这种方式解决该问题来绕过该问题:

Our application needs the ability the access the entire filesystem and all system resources. This is an issue since UWP apps are sandboxed. However, we are trying to bypass that issue by trying to approach it in this manner:

  • Windows 服务 -> 始终在系统上运行.这将承载访问和修改的核心功能系统资源.

  • Windows Service -> Running on the system at all times. This will host the core functionality when it comes to accessing and modifying system resources.

UWP 应用程序 -> 由于 UWP 是沙盒化的,UWP 应用程序会将所有系统请求转发给 Windows 服务,Windows 服务将完成所有工作首当其冲的工作,然后返回输出.

UWP Application -> Since UWP is sandboxed, the UWP app will forward all system requests to the Windows Service, which will do all of the brunt work and just return the output.

我们可以在 WPF 中简单地做到这一点,但我们希望使用 UWP 来利用 WPF 缺乏的一些新的 Windows 10 核心功能,例如动态磁贴和 Cortana.

We can simply do this in WPF, but we would like to use UWP in order to utilize some new Windows 10 core features WPF is lacking such as live tiles and Cortana.

您认为我们的方法可行吗?我们的不确定因素之一是如何让 UWP 应用与 Windows 服务通信 - 我们已经研究了 SignalR 和桌面桥之类的东西,但不确定哪种方法可能是我们方案的最佳方法.

Do you think our approach is feasible? One of our uncertainties is how we can get the UWP app to communicate with the Windows Service- we've looked into things like SignalR and the Desktop Bridge but are unsure which may be the best approach for our scenario.

谢谢!

推荐答案

您认为我们的方法可行吗?

Do you think our approach is feasible?

我们不能直接在 UWP 应用中使用 Windows 服务.为了在 Win32 应用程序和 UWP 应用程序之间建立 IPC,这里可能有帮助的是使用新的 Capability <rescap:Capability Name="runFullTrust"/>,它启用 Win32 应用程序由 FullTrustProcessLauncher API 启动,以实现使用 WinRT API 的上级应用安全上下文.但是正如您在此处看到的 rescap,这意味着此 UWP 应用无法在 Store 中发布.

We cannot directly consume a Windows Service in an UWP app. In order to make the IPC between Win32 app and UWP app, what may help here is using the new Capability <rescap:Capability Name="runFullTrust" />, and it enable the Win32 app which is launched by the FullTrustProcessLauncher API to achieve the uplevel app security context to consume WinRT APIs. But as you see the rescap here, it means this UWP app cannot be published in Store.

可以参考官方AppService Bridge Sample.您可以尝试首先创建一个使用 应用服务(可与 WPF 和 UWP 应用通信,而不是传统的 Windows 服务)并使用 WinRT API,构建此后应用程序(不要运行它),将生成一个 .exe 文件.但是这个应用程序无法运行,因为它使用了 WinRT API,那么你可以创建你的 UWP 应用程序来使这个桌面应用程序可执行.

You can refer to the official AppService Bridge Sample. You can try to firstly create a traditional desktop app which consume App service (which can communicate with WPF and UWP app, not traditional Windows service) and use WinRT APIs, after building this app (don't run it), a .exe file will be generated. But this app cannot run since it uses WinRT API, then you can create your UWP app to make this desktop app executable.

我们已经研究了 SignalR 和桌面桥之类的东西,但不确定哪种方法可能是我们方案的最佳方法.

we've looked into things like SignalR and the Desktop Bridge but are unsure which may be the best approach for our scenario.

所以我认为桌面桥可能是最好的方法.

So I think the Desktop Bridge may be the best approach here.

这篇关于UWP 应用程序与 Windows 服务的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆