Is there some way to pass an object to a windows service? I know the method myServiceController.Star(string[] arg) but i need to pass a more complex object than a string array. Actually, i don't need the object to be passed as a parameter, what i really needs is that the service can use an object created in a windows forms application. I've tried using System.Web.Script.Serialization.JavaScriptSerializer.Serialize method to convert the object into a Json but i couldn't because the object contains a circular reference. I also tried using pointers, but i couldn't becouse it is a managed type object.
Any idea what can i do?
Rather than trying to pass the object itslef (which will not work since the service executes in a separate process) - pass an exernal reference to the data. For example, the path to the file containings the serialized object.
I'm assuming your service is also implemented in .NET? If so, then use binary serialization (BinaryFormatter) as this will handle the circular references. You can then deserialize in your service by loading from the named file.
You might want to consider what happens if the user restarts your service - where does it get the data from in that case? There will be no startup parameters. It may be more robust to use the registry to store the filename of the serialized object, and have your service read from this on startup. Then it will always find the data even when invoked without startup parameters, as is the case the machine reboots, or the user restarts the service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With