简体   繁体   English

帮助创建Windows Server

[英]help with creating windows server

i'm ASP.NET programmer and have no experience in creating windows services. 我是ASP.NET程序员,没有创建Windows服务的经验。 Service i need to create should send emails to our customers each specified period of time. 我需要创建的服务应在每个指定的时间段向我们的客户发送电子邮件。 This service should solve issue when hundreds of emails are sent at the same time and block SMTP service on the server while there are many periods of time when SMTP is on idle without sending anything. 当同时发送数百封电子邮件并阻止SMTP服务在许多时间段内处于SMTP空闲状态而未发送任何内容时,此服务应解决问题。

Idea is to create a service that i will send whole email and address to, inside of the service i will have some type of dataset ( i don't know which one should i use in winforms/winservices) and some basic timer functionality (ie. each 3 seconds get first mail and send it)... Thing is that there are two main types of mails, registration mails which should be main priority and reminder mails (ie. you haven't entered a site for month ) which have low priority. 我的想法是创建一个将向其发送整个电子邮件和地址的服务,在服务内部,我将具有某种类型的数据集(我不知道我应该在winforms / winservices中使用哪种)和一些基本的计时器功能(即。每3秒就会收到第一封邮件并将其发送)...问题是有两种主要类型的邮件,应优先考虑的注册邮件和提醒邮件(即您没有进入一个月的网站)低优先级。 I prefer to create this priority issue with two data sets, when main one is empty less important one sends. 我倾向于用两个数据集来创建此优先级问题,当主要数据集为空时,不重要的数据集将发送。

Another issue is how do i access this service from asp.net application on the same server? 另一个问题是如何从同一服务器上的asp.net应用程序访问此服务?

How would you write that in code or at least point me how to, i know there are many explanations on MS website on basic services but as i don't know much about issue i prefer having it explained in here. 您将如何用代码编写该代码,或者至少指出我该怎么做,我知道MS网站上有关基本服务的解释很多,但是由于我对问题了解不多,所以我希望在此处进行解释。

Thanks for your time. 谢谢你的时间。

I suggest you look at the various email marketing services that are available, many offer APIs or at least an process that you could automate via .Net code. 我建议您查看可用的各种电子邮件营销服务,其中许多提供API或至少可以通过.Net代码自动执行的过程。 I really would avoid trying to set-up your own mail server as keeping it operational, even when legitimate, is hard as any mistaken abuse will get you black-listed and it takes a long time to get white-listed (lots of ICANN-abiding, legitimate activity) so having to start again from a new IP is frustrating. 我真的会避免尝试设置您自己的邮件服务器,因为即使在合法的情况下也要保持运行正常,这是很难的,因为任何错误的滥用都会使您进入黑名单,并且白名单需要很长时间(很多ICANN-持续的合法活动),因此不得不从新IP重新开始令人沮丧。

Work with the professionals in this space, ensure they follow ICANN processes and procedures (and that you do as well), and you'll find they have everything you need and save you a mountain of hassle. 与这个领域的专业人员合作,确保他们遵循ICANN的流程和程序(并且您也照做),您会发现他们拥有所需的一切并为您省去了很多麻烦。

As for creating a web service, there is a ton of examples aout there, just google for "c# windows service example" . 至于创建Web服务,那里有很多示例,例如google的“ c#Windows服务示例”。 Just two examples: 仅举两个例子:

For data exchange: I would store the necessary actions in a database table and scan these tables regularily from the service. 对于数据交换:我将必要的操作存储在数据库表中,并定期从服务中扫描这些表。 Otherwise you could use .NET remoting or message queues or .NET WCF . 否则,您可以使用.NET远程处理或消息队列或.NET WCF。

hth hth

Mario 马里奥

First of all, you don't need a windows service at all, if you know how to send an e-mail from your asp.net app. 首先,如果您知道如何从asp.net应用程序发送电子邮件,则根本不需要Windows服务。 Read on... 继续阅读...

I had a problem similar to yours because ISP that I had my site on was having a limit on e-mails that it can deliver in a day. 我遇到了与您类似的问题,因为我在我的网站上使用的ISP限制了一天之内可以发送的电子邮件。 So I created database table with e-mails, and stored them in there, and created one web page that checked the limits that are in effect, determined if it's safe to send an e-mail, and sends it if it is. 因此,我用电子邮件创建了数据库表,并将其存储在其中,并创建了一个网页来检查有效的限制,确定是否安全发送电子邮件,然后发送电子邮件。

After sending (or not sending) - that page slept for a while (you can insert Sleep() into it - don't use any loops because it will consume your CPU) and then triggered itself via http request again, if there is more mail to be sent. 发送(或不发送)后-该页面休眠了一段时间(您可以将Sleep()插入其中-不要使用任何循环,因为它会消耗您的CPU),然后再通过http请求再次触发自身,如果还有更多的话要发送的邮件。

Every page that filled the mail queue also triggered mail sending page, so it doesn't run when queue is in fact empty. 填充邮件队列的每个页面也会触发邮件发送页面,因此,当队列实际上为空时,它不会运行。

I guess, either that, or you really go for services. 我想,要么是这样,要么您真的会寻求服务。

Create CONSOLE application. 创建CONSOLE应用程序。

Create 2 queues in the database. 在数据库中创建2个队列。 For the e-mails. 对于电子邮件。

In console application, poll the queues periodically, and send e-mails when this is appropriate. 在控制台应用程序中,定期轮询队列,并在适当时发送电子邮件。

Don't go service until you are happy with application as it is. 在对应用程序满意之前,不要去服务。

When debugged completely, create the service, install it and let it run. 完全调试后,创建服务,安装并运行它。

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

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