如何WCF服务我的winform应用程序进行交互? [英] How does the WCF service interact with my winform app?

查看:268
本文介绍了如何WCF服务我的winform应用程序进行交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发,我打算让它与服务器交互一个C#Windows窗体应用程序。服务器将收到来自发布一个移动应用程序,我已经开发,每当收到一个帖子,我的Windows窗体应用程序应通知并给我通知。为了做到这一点,我打算使用WCF双工服务吧。

I am currently developing a C# Windows Form Application that I intend to let it interact with a server. The server will receive posting from a mobile application that I have developed and whenever a posting is received, my Windows Form Application should be notified and give me a notification. In order to do this, I intend to use WCF duplex service for it.

例如。我的手机应用程序发送张贴到我的服务器。一旦我的服务器读取和接收新发布,该服务应在发送邮件到我的winform应用程序来提醒我,一个帖子被接收。而winform应用程序的UI应该相应地更新什么,我想更新。 (例如添加新的面板)

E.g. My mobile application sends an posting over to my server. Once my server reads and receives the new posting, the service should send a message over to my winform app to alert me that a posting is received. And the UI of the winform app should update accordingly to what I want to updated. (e.g. adding new panels)

这基本上是我多么希望为它工作
他们的方式,这将是工作

This is basically how I wish for it to work They way this would work is


  1. WCF服务在我的服务器上运行

  2. Windows窗体连接到使用双面合约
  3. 我的服务器上的WCF服务
  4. 移动应用的帖子到网页

  5. 一旦接收到网页张贴,在asp.net将调用WCF服务

  6. WCF双工服务接收张贴和发送信息到winform应用程序

  7. 我的WinForm应用程序又名WCF客户端更新UI与这个新收到的消息

  1. WCF Service in running on my server
  2. Windows Form connects to my server's WCF service using Duplex Contract
  3. Mobile app posts to a webpage
  4. Once the webpage receives the posting, the asp.net will invoke the WCF service
  5. WCF duplex service receives the posting and sends the information to the winform app
  6. My winform Application aka WCF Client updates UI with this new message received

我的问题是,如何第4步继续第5步?具体地说,请问该服务在收到邮寄过来的winform应用程序发送的信息。

My question is, how does step 4 proceed to step 5? To be specific, how does the service sends the information over to the winform app upon receiving the posting.

要更加具体,一旦过帐从网页接收,服务合同被调用且信息由服务发送和接收,如何服务利用回叫信道的超过信息发送到winform应用程序,并相应更新UI?

To be even more specific, once the posting is received from the webpage, the service contract is invoked and the information is sent and received by the service, how does the service make use of the call back channel to send the information over to the winform app and update the UI accordingly?

推荐答案

在这个问题的答案取决于你的WCF服务托管方式,以及如何大的服务最终将(在并发客户数量而言)。

The answer to this question depends on how your WCF service is hosted and how "big" the service will eventually be (in terms of number of simultaneous clients).


  • 最简单的情况是自承载WCF服务(托管意在Windows服务或作为一个桌面应用程序 - 不是IIS)。在这种情况下,你可以使用 InstancePerSession 模式,使您的业务使用的会话。在这种情况下,你将有一个1:客户端和服务类的实例之间的一一对应。当客户端连接,检索回调参考并将其存储在静态列表服务类的外部。当您需要将消息发送给一个或多个客户,只需遍历(或找到所需的客户端)的列表,并调用回调合同上相应的功能

  • 如果您需要托管在IIS服务,那么情况就麻烦,因为你必须托管服务的多个流程的可能性,所以你的列表可能获得零碎(或一个应用程序池回收的事件交口称赞) 。在这种情况下,你将不得不使用一些外部服务(MSMQ,也许)通知的其他的要发送一条消息需要的应用程序池的进程。

  • The simplest scenario is a self-hosted WCF service (meaning hosted in a Windows Service or as a desktop application--not in IIS). In this case, you can use InstancePerSession mode and make your service use sessions. In this case, you'll have a 1:1 correspondence between clients and instances of your service class. When a client connects, retrieve the callback reference and store it in a static list outside of the service class. When you need to send a message to one or more clients, simply iterate over (or find the desired client in) your list and call the appropriate function on the callback contract
  • If you need to host your service in IIS, then the situation is trickier because you have the possibility of multiple processes hosting your service, so your list can potentially get fragmented (or blown away in the event of an app pool recycle). In this case, you'll have to use something external to your service (MSMQ, perhaps) to notify other application pool processes that a message needs to be sent.

这篇关于如何WCF服务我的winform应用程序进行交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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