Passing an object as a parameter to a Windows service

Is there a 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 that needs to be passed as a parameter, I really need the service to be able to use the object created in the Windows forms application. I tried using the System.Web.Script.Serialization.JavaScriptSerializer.Serialize method to convert the object to Json, but I could not, because the object contains a circular reference. I also tried using pointers, but I could not, because it is an object of a managed type.

Any idea what I can do?

+5
source share
4 answers

Instead of trying to pass itslelef object (which will not work because the service is running in a separate process), pass a data reference. For example, the file path contains a serialized object.

I assume your service is also implemented in .NET? If so, use binary serialization ( BinaryFormatter ), as this will handle circular references. Then you can perform deserialization in your service by downloading from the specified file.

, , , - ? . , . , , .

+3

Windows Windows, XML . ( ), , , - .

0

, Windows. -, / ( .NET 4.0), .

Your question mentions the method (string [] args), which is more like the "main" command line method. In this case, you are probably looking at the wrong thing if it is a Windows service. You do not run the Windows EXE utility to pass its arguments .... no, if you want it to run as a service.

Each of these methods includes its own quirks. But basically, you should marshal your data by serializing links or values.

0
source

All Articles