【发布时间】:2015-09-14 11:02:06
【问题描述】:
我必须从我的 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();
我收到以下异常:
服务无法启动。 System.AggregateException:AggregateException_ctor_DefaultMessage ---> System.Net.WebException:远程服务器返回错误:(400)错误请求。 在 System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 Microsoft.AspNet.SignalR.Client.Http.HttpHelper.c__DisplayClass2.b__0(IAsyncResult ar) 在 System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endMethod,TaskCompletionSource`1 tcs) --- 内部异常堆栈跟踪结束 --- 在 System.Threading.Tasks.Task.Wait(Int32 毫秒超时,CancellationToken 取消令牌) 在 System.Threading.Tasks.Task.Wait() 在 c:\Users\anilcaliskan\Desktop\WindowsFormsApplication1\WinSer35\WinSer35.cs:line 28 中的 WinSer35.WinSer35.OnStart(String[] args) 在 System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(对象状态) --->(内部异常#0)System.Net.WebException:远程服务器返回错误:(400)错误请求。 在 System.Net.HttpWebRequest....
在 .net framework 4.5 上运行并引用默认 Microsoft.AspNet.SignalR.Client dll 的相同代码片段按预期工作。
你有什么建议吗?想想我还有一些其他依赖项,我无法在高于 .net framework 3.5 的版本中编译我的 Windows 服务。
【问题讨论】:
-
如果它真的是 3.5 库,它甚至不应该有这些方法,因为那是 4.5 代码
-
谢谢@Anders。我想你是对的。我找到了一种将我的 Windows 服务升级到 .net 框架 4.5 的方法。如果您将评论添加为答案,我会接受。
标签: c# windows-services signalr owin signalr.client