How can a self-hosted (WinForm ) WCF service interact with the main form?

前端 未结 3 473
借酒劲吻你
借酒劲吻你 2020-12-10 09:33

Simplified version of what I\'m trying to achieve:

  • I have a WinForms app that runs hidden (Visible = false) in the background.
  • It\'s got only one Form
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 10:22

    In my opinion the answer is "simpol" as a friend says. First of all I would not even bother to follow the path described by you, after all a web service provides all the necessary means to communicate with it. Between your Form1 (which host your service) and your hosted service add a client (where client code is hosted by same Form1) and allow your client to communicate with your service using a duplex channel. In this way your client will know if a message was sent to your service by initiating a a long running request and being notified through the callback. Here is a link with a fancy article related to duplex channels: http://blogs.msdn.com/b/carlosfigueira/archive/2012/01/11/wcf-extensibility-transport-channels-duplex-channels.aspx

    P.S: This is a rough suggestion to get you started which for sure can be improved.

提交回复
热议问题