Windows 8 中的 Metro 应用程序如何与同一台机器上的后端桌面应用程序通信? [英] How can a Metro app in Windows 8 communicate with a backend desktop app on the same machine?

查看:29
本文介绍了Windows 8 中的 Metro 应用程序如何与同一台机器上的后端桌面应用程序通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您使用适用于 Windows 8 的新 Metro 风格应用程序构建了 UI 前端,并希望它与在同一台本地计算机上的桌面上运行的 .NET 应用程序(例如 Windows 服务应用程序)进行通信).

In a situation where you have the UI frontend built using the new Metro style of apps for windows 8, and would like it to communicate with a .NET application running on the desktop on the same local machine (e.g. a windows service app).

metro 应用和桌面应用之间可以使用哪些进程间通信形式?

What forms of interprocess communication are available between the metro app and the desktop app?

感谢 Visual Studio 团队的 Pavel Minaev,他在评论中提供了一些初步信息,引用:

Thanks to Pavel Minaev of the Visual Studio team, who has provided some initial info here in a comment, quoted:

根据 Martyn Lovell 的说法,没有任何刻意的机制那个,以及一些可以用于它的被故意限制.例如,命名管道不存在,内存映射文件也不存在.有套接字(包括服务器套接字),但是当连接到localhost,你只能连接到同一个应用程序.你可以正常使用共享已知文件夹"之一(文档、图片等)中的文件,但这是一个相当粗糙的黑客,需要进行轮询并且是对用户可见.-- Pavel Minaev 评论 这个问题

According to Martyn Lovell, there isn't any deliberate mechanism for that, and some that could be used for it are intentionally restricted. Named pipes aren't there, for example, nor are memory mapped files. There are sockets (including server sockets), but when connecting to localhost, you can only connect to the same app. You could use normal files in one of the shared "known folders" (Documents, Pictures etc), but that is a fairly crude hack that necessitates polling and is visible to the user. -- Pavel Minaev commenting on this issue

因此失败的正常方法我正在考虑使用 Web 服务或读取/写入数据库以进行某种形式的通信,当进程在同一台机器上运行时,这两种方法似乎都有些矫枉过正.

So failing normal approaches I was thinking of using web services or reading/writing to a database in order to get some form of communication happening, both of which seem like overkill when the processes are running on the same machine.

我在这里尝试的东西有意义吗?我可以看到需要将 Metro 应用程序作为在桌面上运行的现有服务的前端 UI.还是仅将 WPF 用于桌面上运行的前端 UI(即非 Metro 应用程序)更好.

Is what I'm attempting here making sense? I can see a need for a metro app to be the frontend UI for an existing service which is running on the desktop. Or is it better to just use WPF for the frontend UI running on the desktop (i.e. a non-metro app).

推荐答案

我现在正在将我现有的项目移植到 Win8.它由 Windows 服务和托盘应用程序组成,它们通过 NamedPipes WCF 相互通信.您可能已经知道 Metro 不支持命名管道.我最终使用 TcpBinding 进行全双工连接.

I'm porting my existing project to Win8 right now. It consists of windows service and tray application which are talking to each other via NamedPipes WCF. As you may already know Metro doesn't support named pipes. I ended up using TcpBinding for full duplex connection.

这篇博文描述了支持哪些功能.

Metro 客户端可以使用的我的 WCF 服务器示例是 此处.

Sample of my WCF server that Metro client can consume is here.

另外请记住,您不能在 Metro 中使用同步 WCF.您必须使用 Task-基于包装器,它只是异步的.

Also keep in mind that you can't use synchronous WCF in Metro. You'll have to use Task-based wrapper which is only asynchronous.

谢谢你的提问.我是一个很好的起点:)

And thank you for you question. I was good starting point for me :)

这篇关于Windows 8 中的 Metro 应用程序如何与同一台机器上的后端桌面应用程序通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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