简体   繁体   中英

How to pass an object to Web Service from its hosting Windows Service

I have a web service, say MyWebService , and I need to host it on a windows service, say MyWindowsService . So in OnStart method in MyWindowsService , I start MyWebService . When MyWindowsService starts, I need to send a log message (from within MyWindowsService ) to a listener saying the application has been started. Such a log message is generated by a LogGenerator .

In MyWebService , it also needs to send log messages to the listener as well when certain events are triggered, and those log messages (sent from within MyWebService ) are also generated by LogGenerator .

The LogGenerator has a few properties to be configured. Now I am facing some issues.

  1. I do not know whether I need to construct an instance of LogGenerator , configure this instance in MyWindowsService , then pass it to MyWebService . If so, then how I can pass an object to the web service from its hosting windows service. Or,

  2. I construct an instance of LogGenerator in MyWindowsService and then I construct a second one in MyWebService , so I do not need to pass any object to the web service. Or,

  3. I can make LogGenerator and all its properties and methods static, so I do not need to create any instances at all. If so, is it thread safe when I create log messages?

Thank you for any input !!!

You could use the singleton pattern when starting the web service to identify it and add event listeners on the windows service. Of course, this only works if you have only one instance of the web service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM