简体   繁体   English

Web应用程序与桌面应用程序之间的双向通信

[英]Two-way communication between web application and desktop application

I am curious if this scenario is even possible: 我很好奇这种情况是否可能:

  1. .Net Windows Forms application (our product) with a couple of WCF services exposed (self hosted, for example on ' http://localhost:8000/myservice/method1 '), running in elevated mode. .Net Windows Forms应用程序(我们的产品),其中包含几个公开的WCF服务(自行托管,例如在' http:// localhost:8000 / myservice / method1 '上),它们以提升模式运行。
  2. A web application (from another manufacturer) on a public domain, which would communicate with our application in a two-way mode: 公共领域的(来自其他制造商的)Web应用程序,它将以双向方式与我们的应用程序进行通信:
    1. web application to desktop application: during the setup of our application we register a custom protocol 'xxx' (similar to 'mailto') and set our application as a handler for this protocol. Web应用程序到桌面应用程序:在安装应用程序期间,我们注册了自定义协议“ xxx”(类似于“ mailto”),并将我们的应用程序设置为该协议的处理程序。 So the web application can trigger an action in our desktop application with links in the form 'href="xxx:parameters"'. 因此,Web应用程序可以使用“ href =“ xxx:parameters””形式的链接来触发我们桌面应用程序中的操作。
    2. desktop application to web application: the web application would periodically (every second for example) poll our localhost WCF services via javascript ajax calls. 桌面应用程序到Web应用程序:Web应用程序将定期(例如每秒)通过javascript ajax调用轮询我们的本地主机 WCF服务。

Is the 2.2 option even possible? 2.2选项甚至可能吗? Which binding should we use for WCF services? WCF服务应使用哪种绑定? Are there any problems with cross domain calls (from public domain to localhost)? 跨域调用(从公共域到本地主机)是否存在任何问题?

Edit - yes, the communication is not two-way because in our scenario the desktop application cannot directly manipulate the web application. 编辑-是的,通信不是双向的,因为在我们的方案中,桌面应用程序无法直接操纵Web应用程序。 The polling option is just an idea how to get state from desktop application to web application, so if there are better alternatives I would very much like to hear about it :) 轮询选项只是一个如何从桌面应用程序获取状态到Web应用程序的想法,因此,如果有更好的选择,我非常想听听它:)

There are a couple of other alternatives for communication between web application and desktop application (java plugins, active x for IE, firefox plugins, chrome native plugin,...) but they are very fragile regarding new versions of browsers, versions of java, version of Windows,... and you have to maintain all of them. Web应用程序和桌面应用程序之间还有其他几种通信方式(Java插件,用于IE的Active X,firefox插件,chrome本机插件等),但是对于新版本的浏览器,Java版本, Windows版本...,则必须维护所有这些。 We are looking for a option which would work on all major browsers and that the manufacturer, which is responsible for web application, would have as little work as possible. 我们正在寻找可以在所有主要浏览器上使用的选项,并且负责Web应用程序的制造商将尽可能少地工作。

Is the 2.2 option even possible? 2.2选项甚至可能吗?

Yes

Which binding should we use for WCF services? WCF服务应使用哪种绑定?

  1. For the incoming calls from the web app (href links) you should expose your service operation as a REST endpoint, using WCF webHttpBinding or something like Nancy , which is much lighter. 对于来自Web应用程序的传入呼叫(href链接),您应该使用WCF webHttpBinding或类似Nancy的东西将您的服务操作公开为REST终结点,这要轻得多。

  2. For the polling, as already mentioned, you need to host another REST endpoint. 如前所述,对于轮询,您需要托管另一个REST端点。

Two-way communication between web application and desktop application Web应用程序与桌面应用程序之间的双向通信

Based on your description, this doesn't appear to be a genuine two-way requirement, as in duplex (calls going both ways). 根据您的描述,这似乎不是真正的双向要求,就像在双工中一样(双向通话)。 In both scenarios you outline the calls originate on the partner website. 在这两种情况下,您都将概述呼叫源自合作伙伴网站。 It's only the responses which travel the other way, or am I missing something? 只是反应是相反的,还是我错过了什么?

The polling option is just an idea how to get state from desktop application to web application 轮询选项只是一个如何从桌面应用程序获取状态到Web应用程序的想法

Strictly speaking, the polling originator is not the web app per se , but the client browser via JavaScript. 严格地说,轮询鼻祖不是Web应用程序本身 ,而是通过JavaScript客户端浏览器。 Apart from any architectural concerns of using a client app as an intermediary between desktop and server, there is a very real complication around implementing cross-origin scripting in the browser. 除了使用客户端应用程序作为台式机和服务器之间的中介的任何架构问题之外,在浏览器中实现跨域脚本编写还存在非常复杂的问题。

I suggest a better solution would be to call the web app from the desktop app when state changes, and then have the web app "notify" the web client, either via ajax polling (to the web app), or something like SignalR . 我建议一个更好的解决方案是在状态更改时从桌面应用程序调用Web应用程序,然后让Web应用程序通过Ajax轮询(到Web应用程序)或诸如SignalR来“通知” Web客户端。

This would likely be not much more work for your partner as although they would need to host a new "Status Changed" endpoint for you to call, the ajax polling task would probably be simpler seeing as they'd be polling their own service rather than yours. 这可能对您的合作伙伴来说并没有更多的工作,因为他们需要托管一个新的“状态已更改”端点供您调用,而ajax轮询任务可能更简单,因为他们将轮询自己的服务而不是你的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .Net桌面应用程序和ASP.NET Web应用程序之间的通信 - Communication between .Net Desktop Application and ASP.NET Web application 桌面应用程序与服务器之间的套接字通信 - Socket communication between desktop application and server 在桌面应用程序和Web应用程序之间是可能的 - is sso posible between Desktop application and web application .Net桌面应用程序和浏览器中的Silverlight应用程序之间的通信 - Communication between a .Net desktop application and a Silverlight application in browser 使用WCF的两个winform应用程序之间的通信? - Communication between two winform application using WCF? 在SERVICE和Web /桌面应用程序之间进行通信 - Communicating between SERVICE and web/desktop application 客户端和服务器之间的安全双向通信,包括大文件附件 - Secure two-way communication between client and server including large file attachments SAAS / Cloud Web应用程序和桌面应用程序之间的共享身份验证 - Shared Authentication between SAAS/Cloud web application and Desktop application 将Web应用程序移植到桌面应用程序 - Porting a Web Application to Desktop Application 桌面应用程序中的 Web API - Web APIs in Desktop application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM