c# - Communication between windows service and ASP.NET web application via wcf -


i tried communicate between windows service , asp.net mvc web application wcf service, self hosted in windows service.

[servicecontract(namespace = "myservice")] public interface imyinterface {     [operationcontract]     string test(string message); }  class message : imyinterface {     public string test(string message)     {         return "message service: " + message;     } }   public partial class myservice : servicebase {     public servicehost servicehost = null;      protected override void onstart(string[] args)     {         if (servicehost != null)             servicehost.close();         servicehost = new servicehost(typeof(message));         servicehost.open();     } } 

my windows service contains thread, running , start, stop und control other external processes. web appliaction should able show state of processes. i'm looking way pass process data web application, i'm not sure solution problem.

after start windows service wcf service use add service reference in visual studio in web application consume wcf service web application. if new page loaded call service way:

myservicereference.mywebclient  myclient = new myservicereference.mywebclient(); myclient.test("hello"); 

if understood right every time when web application call service new instance of class message created. need runtime values existing instance in windows service. first idea use static variables, can accessed clients. read there single instance mode.

[servicebehavior(instancecontextmode = instancecontextmode.single)]  class message : imyinterface { } 

and think in windos service can pass singleton instance service host.

servicehost = new servicehost(messageobject, ...); 

i'm not sure if right way? better share process data via file or database? or there other better solutions problem?


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -