Click here to Skip to main content
15,897,891 members

Control Windows Service by Asp.net Web application

saichaitanya.kumar asked:

Open original thread
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
C#
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();
            }

        }

and in my web.config I added key also
<identity impersonate="true" />


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.
Tags: Windows, Service

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900