通过Asp.net Web应用程序控制Windows服务 [英] Control Windows Service by Asp.net Web application

查看:127
本文介绍了通过Asp.net Web应用程序控制Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当管理员从管理站点上载新的pdf文件时,我有一个要求每月向订阅的用户发送一封新闻信.在这里订阅的用户接近5lacks用户.
因此,我为后台进程创建了一个Windows服务.管理员上载新的pdf时,请单击发送"按钮,然后调用Window Service并通过此邮件服务向所有用户发送邮件.
这是我在Web应用程序中的代码

Hi,
I have one requirement sending a news letter for subscribed users for every month, when admin uploads a new pdf file from the admin site. Here subscribed users are nearly 5lacks users.
So, I created a windows service for background process. When admin uploads a new pdf, click Send button then invoking Window Service and sending mails to all the users by this mail service.
This is my code in web application

private void StartServiceByName(string serviceName)
        {
            ServiceController serviceController = new ServiceController(serviceName);
            try
            {
                serviceController.MachineName = ConfigurationManager.AppSettings["ServerName"]; //this is my computer name "dt-corp-pms-04";
                serviceController.ServiceName = ConfigurationManager.AppSettings["ServiceName"]; //This is my Service name"Service1";
                serviceController.Start();
            }
            catch (Exception ex)
            {
                ExceptionLog objExceptionLog = new ExceptionLog();
                objExceptionLog.SaveException(ex.ToString(), ex.Message);
                if (serviceController.Status == ServiceControllerStatus.Running)
                    serviceController.Stop();
            }

        }


在我的web.config文件中,我还添加了


and in my web.config I added key also

<identity impersonate="true" />



当我测试Web应用程序,运行Windows服务并将邮件发送给所有用户时,这在我的本地计算机上运行良好.
但是,当我在客户端服务器上部署此Web应用程序时,我收到消息无法在计算机"MyClientComputerName"上打开"MyService"服务
我托管了Web应用程序,并将Windows服务安装在客户端的同一台计算机上.

请帮助我.



This is working fine in my local machine when I am testing my web application, the windows service is running, and sending the mail to all the users.
But When I deployed this web application on my client server, I am getting the message Can not open "MyService" Service on computer "MyClientComputerName"
I hosted my web application and installed my windows service on my client''s same machine.

Please help me.

推荐答案


请尝试以下链接...

> http://stackoverflow.com/questions/6453447/cannot-open-myservice-service-在计算机上 [ ^ ]

http://forums.asp.net/t/1685173.aspx/1 [ ^ ]

http://social.msdn.microsoft.com/Forums/zh/csharpgeneral/thread/27594f64-f223-4457-b469-d9262f3908ad [
Hi
Please try the below links...

http://stackoverflow.com/questions/6453447/cannot-open-myservice-service-on-computer[^]

http://forums.asp.net/t/1685173.aspx/1[^]

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/27594f64-f223-4457-b469-d9262f3908ad[^]

Regards
Sebastian


如果服务器位于共享主机环境中,则可能会出现此问题.请确保您托管的应用程序是完全信任"应用程序.我相信与服务进行交互就像是管理任务.大多数(如果不是全部)托管服务提供商会将应用程序保持在中等信任级别.

如果您有专用服务器,则需要配置一个可以启用和禁用服务的帐户,然后在identity标记中提供其凭据,如下所示:

The issue can arise if the server is in Shared Hosting environment. Please make sure that the application you have hosted is a Full Trust application. I believe interacting with the services is like a Admin task. Most, if not all hosting providers keep the application in the medium trust levels.

If you have a dedicated server, you need to configure an account which can enable and disable services and then provide its credentials in the identity tag like this:

<identity impersonate="true" userName="accountname" password="password" />



在您的本地计算机上,它运行良好,因为很可能您正在以管理员权限运行Visual Studio.



On your local machine it works fine because most probably you are running Visual Studio with Administrator rights.


这篇关于通过Asp.net Web应用程序控制Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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