简体   繁体   English

WCF如何服务于通信渠道?

[英]How is WCF service a communication channel?

My project requires me to execute a windows service that performs some back-end operations while a WPF GUI displays information to the user and also allows the user to do some configurations. 我的项目要求我执行Windows服务,该服务执行一些后端操作,而WPF GUI向用户显示信息,并且还允许用户进行一些配置。 To be more precise my back-end service performs anti-malware operations indefinitely while the GUI needs to communicate with the service to fetch data and for enable/disable operations. 更精确地说,我的后端服务会无限期地执行反恶意软件操作,而GUI需要与该服务进行通信以获取数据并启用/禁用操作。

Now for this communication between the GUI and my service I researched on this forum and majority of people suggested using WCF service hosted in my original service. 现在,为了在GUI和我的服务之间进行这种通信,我在这个论坛上进行了研究,大多数人建议使用原始服务中托管的WCF服务。 I have done just that, hosted a WCF service in my back-end service Onstart() function. 我已经做到了,在后端服务Onstart()函数中托管了WCF服务。 My GUI is also able to reference the WCF service and the buttons can call the WCF hosted functions. 我的GUI也可以引用WCF服务,并且这些按钮可以调用WCF托管的函数。

Now I don't understand how WCF will communicate with the service that is hosting it. 现在,我不了解WCF如何与托管它的服务进行通信。 This is because the purpose of using WCF was to build a communication channel between the GUI and my original windows service. 这是因为使用WCF的目的是在GUI和我的原始Windows服务之间建立通信通道。 I want to expose the windows service functions to the GUI and not those I have written in the WCF service. 我想将Windows服务功能公开给GUI,而不是我在WCF服务中编写的那些服务。 I have researched a lot and cannot find relevant articles. 我研究了很多,找不到相关的文章。 Someone please help me to call my windows service function when a button is pressed on the GUI. 当在GUI上按下按钮时,请有人帮助我调用Windows服务功能。 If there are articles already existing please refer me to them. 如果已有文章,请转给我。 I am short of time and any help will be highly appreciated. 我没有时间,任何帮助将不胜感激。

If your WCF service should call your windows service's methods and they are in different assemblies, the easiest way might be to extract the methods you want to call from the windows service in an interface. 如果WCF服务应调用Windows服务的方法并且它们在不同的程序集中,则最简单的方法可能是在界面中从Windows服务中提取要调用的方法。 Put that interface into the WCF service's assembly and take one such object as constructor parameter for example. 将该接口放入WCF服务的程序集中,并以一个这样的对象作为构造函数参数为例。 Then work against that. 然后反对那个。 Reference the WCF service assembly in your windows service, and pass the service to the WCF service after you have made the windows service implement the required interface. 在Windows服务实现所需的接口之后,请在Windows服务中引用WCF服务程序集,并将该服务传递给WCF服务。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM