i’d like to create a windows service that would be accessible via WCF from a web application.
The workflow would be:
- Windows Service starts and would hold a default value in memory.
-
A web app would connect the windows service via wcf and take the value and after some processing set the value back in the memory.
-
In a while would happend the same as in point 2., and so on,so on
This value would be hold only in memory.
The point is I dont know where put the variable that would be hold in the memory of the windows service.There is a Service class wich is instancied in a Program class wich is static class. So whats the best place to put a variable that would be hold in the memory as long as the service is running ?
And second question,is it correct to reference the exe of the windows service in a DLL ??
There is a service class for every windows service that also contains the start and stop methods. However, for your service, I’d simply create a singleton class that is accessed from the class that handles the WCF client requests.
There’s no need to reference the exe of the service (and I strongly recommend you not to do that), as when you’re using WCF you’ll insert a service reference into your client project and just need two methods to get and set the data.
I suggest: Design your operation and data contracts for the service and then create the service reference within your client project. That’ll make things clear.
If you don’t know what I’m talking about, I recommend googleing for WCF samples.
EDIT
You write in the comment that you created a service class with a private field. I suppose you didn’t actually do what I suggested 🙂 I said: Create a singleton class that is accessed by the class that handles the get/set requests.
So now you have a window service class that you use to host a WCF service. The WCF service contains methods to get/set the value from
ValueHolder.Instance.SomeValue. These methods are exposed to the client using the data contract.Start your service and add a service reference to the client using the respective option in Visual Studio (not a reference to the DLL, but a service reference!!). The client now accesses the get/set methods of the service.
Job done, where’s my money? 😀