网站和Windows服务通信 [英] Web Site and Windows Service Communication

查看:59
本文介绍了网站和Windows服务通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Freinds,



我必须开发网络设备监控软件。我希望它分为两部分。

1. Windows服务

2.在IIS上运行的网站

首先将是一个Windows服务,它将轮询网络设备,查询数据库并发送通知网站(在同一服务器上运行),负责演示。



请帮助Windows服务如何通过C#与IIS7托管网站进行通信。示例将被拨出。



提前谢谢。

Hi Freinds,

I have to develop a Network device monitoring software. I want it to divide in two part.
1. Windows Service
2. Website running on IIS
First will be a windows Service which will poll network device, query database and send notification to Website ( running in same server) which will responsible for presentation.

Please help how can a Windows Service communicate to a IIS7 hosted website in C#. Example will be appropriated.

Thanks in advance.

推荐答案

究竟是什么?

你到目前为止尝试了什么,你在哪里被困?这不是一个快速回答类似的热门话题。我们不会做你的工作,这个社区被要求帮助你通过具体的技术问题。根据你所写的内容,你有一套要求,不知道如何开始。嗯,这对你不好。首先,因为您的方法看起来不正确。对于服务轮询设备,这没关系。但是网站是被动的,它会对客户端请求作出反应,因此您可能会发现Web应用程序被杀死(取决于页面加载,实际上经常是这样) - 因此您无法通知它。另一种方法是正确的方法:客户端(如果有的话)应该请求IIS和Web应用程序以便更新演示文稿 - 例如使用ajax调用。 Web应用程序可以轮询数据仓库(数据库)或服务本身以获取新数据。这是旧的scool方法。



但是您可以考虑使用一些技术,例如跳过IIS并使用Windows服务本身托管的WebAPI,或者让客户端使用使用WebSocket等直接联系Windows服务......



如您所见,您需要规划一个良好的架构设计,环顾可用的技术和方法,受到你没有告诉我们的其他要求的限制。但所有这些都从属于整个解决方案的实际使用,这一点从你所写的内容中并不清楚。
Example for what exactly?
What have you tried so far, where are you stuck? This is not a "quick answers" kind top topic. We won't do your job, this community is pelased to help you pass trough concrete technical problems. Based on what you wrote, you have a set of requirements, and no idea how to start. Well, that's bad for you. First of all, because your approach looks incorrect. As far as the service is polling the devices, that's fine. But the website is passive, it will react on client requests, so you might find the web application killed (depending on page load, wery often actually) - so you can't notify it. The correct approach is the other way: the client (if there is any) should request IIS and the web application for data to update the presentation - using an ajax call for example. The web application could poll the databstore (database) or the service itself for new data. This is the old scool approach.

But there are some technologies you might consider using, like skipping IIS and using WebAPI hosted in the Windows Service itself, or letting the client contact the Windows Service directly using WebSocket and so on...

As you can see, you need to plan a good architectural design, look around available technologies and methods, constrainted by your other requirements you haven't told us. But all this is subordinated to the actual use of the whole solution, which is not clear from what you wrote.


既然你是这个领域的新手,你首先需要了解WCF(Windows Communcation Foundation)和客户端(在您的情况下是一个网站)的概念。第一步是创建服务,实际上是由主机实现的接口。主机可以是任何可以接受客户请求的东西;大多数情况下只是一个控制台应用程序。然后你将创建一个简单的库,它将用于实现你的服务接口,并为它添加功能(如果你的界面中有空函数,那么你也需要声明它们)。



完成后,您只需在您的网站中使用这些服务(在您的网站中添加服务参考),即可使用这些服务库。添加后,您可以继续使用这些资源并调用方法来执行不同的任务。



阅读关于此主题的文章,并下载示例想要测试这个功能。 通过Internet创建连接设备使用的Web服务 [ ^ ]
Hi, since you're a newbie to this field, you first need to understand the concept of a WCF (Windows Communcation Foundation) and the client (which in your case is a website). First step is to create the service, which in real is an interface to be implemented by a host. The host can be anything that can accept the requests from clients; in most cases is just a Console application. Then you will create a simple library, which will be used to implement the interface of your service, and add the functionality to it (if you've got the empty functions in your interface then you need to declare them too).

Once done, you can simply just use those services (Add service reference in your website) in your website, to consume those service libraries. Once added, you can then follow on to use those resources and call the methods to perform different tasks.

Read my article on this topic, and download the sample if you want to test this functionality. Creating a Web Service to be consumed by connected Devices via Internet[^]


这篇关于网站和Windows服务通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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