1
votes

I have windows service created on my machine and another WCF service created and hosted. I wanted to know how to communicate WCF service and Windows service using Signalr. The problem is like I don't know how to couple both WCF and windows service together to make the connection tight.

The other hand if my WCF service has some data I want to pass that data to windows service instantly.

Here is the code snippet I have in my windows service.

namespace POCWindowsService { public partial class TestService : ServiceBase { System.Timers.Timer timeDelay; int count;

    public TestService()
    {
        InitializeComponent();
        timeDelay = new System.Timers.Timer();
        timeDelay.Elapsed += new System.Timers.ElapsedEventHandler(WorkProcess);

    }

    public void WorkProcess(object sender, System.Timers.ElapsedEventArgs e)
    {
        string process = "Timer Tick" + count;
        LogService(process);
    }

    protected override void OnStart(string[] args)
    {
        LogService("POC Service Started");
        timeDelay.Enabled = true;

    }

    private void LogService(string content)
    {
        FileStream fs = new FileStream(@"F:\Test\TestServiceLog.txt", FileMode.OpenOrCreate);
        var sw = new StreamWriter(fs);
        sw.BaseStream.Seek(0, SeekOrigin.End);
        sw.WriteLine(content);
        sw.Flush();
        sw.Close();
    }

    protected override void OnStop()
    {
        LogService("POC Service Stopped");
        timeDelay.Enabled = false;

    }
}

}

My WCF service runs on http://localhost:8080/ and my windows service name POCWindowsService.

I want to know how can I connect these two services using Signalr.

Thanks

1

1 Answers

0
votes

I don't think its WCF related question. all you need is adding the signal R library to your service and then call it. perhaps something like this:

private async void ConnectAsync()
{
    Connection = new HubConnection("http://localhost:8080");
    HubProxy = Connection.CreateHubProxy("YourHub");

    //Handle incoming event from server: use Invoke to write to console from SignalR's thread
    HubProxy.On<string, string>("YourMethod", (params1, params2) => Invoke((Action)(() => LogService(String.Format("{0}: {1}" + Environment.NewLine, params1, params2)))));

    await Connection.Start();
}