Obtain an instance of a windows service in .NET

Posted on 2004-11-05
Last Modified: 2010-04-17
I wrote a windows service using c#.  It communicates with my application using .net remoting.  I can obtain an instance of my service using .net remoting, however using the methods is too much slower than doing the method within the application.

Is there a way to obtain an instance of the service so I can execute its methods directly?  I know I can get a ServiceController object based on the service name.  Is there a way for my application to get the instance itself, so that I can execute

Or is remoting the only way?
Question by:lynx2sw1
    LVL 23

    Expert Comment

    Modify the service to respond to custom messages and use ControlService() to pass them:

    LVL 1

    Author Comment

    I had thought those custom message parameters were only integers, without a control value.  I want to pass in other things than intts, a

    I am coding in C#.  But I followed your link and it gave me the idea to try to use kernal32 in my c#.  
    [DllImport("advapi32.dll", EntryPoint="OpenService")] public static extern int OpenServiceA(int hSCManager, string lpServiceName, int dwDesiredAccess)
    LVL 23

    Accepted Solution

    Well, yes, you have to use OpenService() to get a handle to the service to tell ControlService() which service's control handler to send the message to.  The value of the message would tell the service which method to call.

    Perhaps you could use object serialization for passing data.  If you don't have too many object types to pass, the custom control code could be used to specify both method and object.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    This article will show, step by step, how to integrate R code into a R Sweave document
    This is about my first experience with programming Arduino.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now