Signalr 客户端作为 .net Framework 3.5 上的 windows 服务 运行
Signalr client as a windows service running on .net framework 3.5
我必须从我的 windows 服务向我的 signalr 集线器发送消息。我的一些 windows 服务 运行 在 .net Framework 3.5 上。我的第一步是添加这个包:
https://www.nuget.org/packages/Nivot.SignalR.Client.Net35/
这是我针对此场景的完整测试代码:
public partial class WinSer35 : ServiceBase
{
private HubConnection hubConnection;
private IHubProxy priceProxy;
public WinSer35()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
hubConnection = new HubConnection("http://localhost:8080/signalr", useDefaultUrl: false);
priceProxy = hubConnection.CreateHubProxy("PriceHub");
hubConnection.Start().Wait();
TestPrice testPrice = new TestPrice() { Id = 1, Buy = 1.2345, Sell = 9.8765, Symbol = "EURUSD" };
priceProxy.Invoke("NotifySubscribers", testPrice).Wait();
}
protected override void OnStop()
{
}
}
在线:
hubConnection.Start().Wait();
我遇到以下异常:
Service cannot be started. System.AggregateException: AggregateException_ctor_DefaultMessage ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Microsoft.AspNet.SignalR.Client.Http.HttpHelper.<>c__DisplayClass2.b__0(IAsyncResult ar)
at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func
2 endMethod, TaskCompletionSource`1 tcs)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at WinSer35.WinSer35.OnStart(String[] args) in c:\Users\anilcaliskan\Desktop\WindowsFormsApplication1\WinSer35\WinSer35.cs:line 28
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
---> (Inner Exception #0) System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest....
相同的代码片段 运行 在 .net Framework 4.5 上运行并引用默认 Microsoft.AspNet.SignalR.Client dll 按预期工作。
你有什么建议吗?想想我还有一些其他依赖项,我无法在高于 .net framework 3.5 的版本中编译我的 windows 服务。
如果它真的是一个 3.5 库,它甚至不应该有那些方法,因为那是 4.5 代码
我必须从我的 windows 服务向我的 signalr 集线器发送消息。我的一些 windows 服务 运行 在 .net Framework 3.5 上。我的第一步是添加这个包:
https://www.nuget.org/packages/Nivot.SignalR.Client.Net35/
这是我针对此场景的完整测试代码:
public partial class WinSer35 : ServiceBase
{
private HubConnection hubConnection;
private IHubProxy priceProxy;
public WinSer35()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
hubConnection = new HubConnection("http://localhost:8080/signalr", useDefaultUrl: false);
priceProxy = hubConnection.CreateHubProxy("PriceHub");
hubConnection.Start().Wait();
TestPrice testPrice = new TestPrice() { Id = 1, Buy = 1.2345, Sell = 9.8765, Symbol = "EURUSD" };
priceProxy.Invoke("NotifySubscribers", testPrice).Wait();
}
protected override void OnStop()
{
}
}
在线:
hubConnection.Start().Wait();
我遇到以下异常:
Service cannot be started. System.AggregateException: AggregateException_ctor_DefaultMessage ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at Microsoft.AspNet.SignalR.Client.Http.HttpHelper.<>c__DisplayClass2.b__0(IAsyncResult ar) at System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func
2 endMethod, TaskCompletionSource`1 tcs) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at WinSer35.WinSer35.OnStart(String[] args) in c:\Users\anilcaliskan\Desktop\WindowsFormsApplication1\WinSer35\WinSer35.cs:line 28 at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state) ---> (Inner Exception #0) System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest....
相同的代码片段 运行 在 .net Framework 4.5 上运行并引用默认 Microsoft.AspNet.SignalR.Client dll 按预期工作。
你有什么建议吗?想想我还有一些其他依赖项,我无法在高于 .net framework 3.5 的版本中编译我的 windows 服务。
如果它真的是一个 3.5 库,它甚至不应该有那些方法,因为那是 4.5 代码