我在我的机器上创建了windows服务,创建并托管了另一个WCF服务。我想知道如何使用Signalr通信WCF服务和Windows服务。问题是,我不知道如何将WCF和windows服务结合在一起,从而使连接更加紧密。
另一方面,如果我的WCF服务有一些数据,我想立即将该数据传递给windows服务。
下面是我在windows服务中的代码片段。
命名空间POCWindowsService {公共部分类TestService : ServiceBase { System.Timers.Timer timeDelay;int计数;
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;
}
}}
我的WCF服务运行在http://localhost:8080/上,我的windows服务名为POCWindowsService。
我想知道如何使用Signalr连接这两个服务。
谢谢
发布于 2018-02-10 08:47:39
我不认为它与WCF相关的问题。您所需要的只是将信号R库添加到您的服务中,然后调用它。也许是这样的:
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();
}https://stackoverflow.com/questions/48712519
复制相似问题