class 库中的 C# SignalR
C# SignalR within a class library
我一直在开发 Web 服务 (C# WebAPI2),因此可以简单地使用 SignalR 发送消息,然后将消息抄本存储在 TSQL 数据库中。但是,在 class 库中移动 SignalR 集线器后,我现在似乎无法访问它们。我开发了一个非常简单的控制台应用程序来与 Web 服务进行通信,但我收到了一个奇怪的异常。
这是抛出的异常:
"StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1,
Content: System.Net.Http.StreamContent, Headers:\r\n{\r\n
Transfer-Encoding: chunked\r\n X-SourceFiles:
=?UTF-8?B?QzpcRGV2ZWxvcG1lbnRcU291cmNlQ29kZVxTVVBTZXJ2aWNlXFNVUC5TZXJ2aWNlXHNpZ25hbHJcbmVnb3RpYXRl?=\r\n
Cache-Control: private\r\n Date: Wed, 11 Mar 2015 10:50:18 GMT\r\n
Server: Microsoft-IIS/8.0\r\n X-AspNet-Version: 4.0.30319\r\n
X-Powered-By: ASP.NET\r\n Content-Type: text/html;
charset=utf-8\r\n}"
An unhandled exception of type 'System.AggregateException' occurred
in SignalR Client Connection.exe
Owin 启动文件位于 Web 服务 App_Start 文件夹中,如下所示:
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.AspNet.SignalR;
[assembly: OwinStartup(typeof(Service.App_Start.Startup))]
namespace Service.App_Start
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true,
EnableJSONP = true
};
map.RunSignalR(hubConfiguration);
});
}
}
}
非常感谢。
我不确定你的情况的细节,但对我来说,我发现我收到了 System.AggregationException:
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at Client.CommunicationHandler.AddMessage(String method, String args, String serverUri, String hubName) in c:\Workspace\EnvisionRealTimeRemoteOps\CodeProjectSelfHostedBroadcastServiceSignalRSample\Client\CommunicationHandler.cs:line 24
at Client.Program.Main(String[] args) in c:\Workspace\EnvisionRealTimeRemoteOps\CodeProjectSelfHostedBroadcastServiceSignalRSample\Client\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.Http.HttpRequestException
HResult=-2146233088
Message=An error occurred while sending the request.
InnerException: System.Net.WebException
HResult=-2146233079
Message=Unable to connect to the remote server
Source=System
StackTrace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=No connection could be made because the target machine actively refused it 127.0.0.1:8083
Source=System
ErrorCode=10061
NativeErrorCode=10061
StackTrace:
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
InnerException:
直到我添加了对以下内容的调用:
WebApp.Start("http://localhost:8083"); // Put your desired URL in...
请注意,在我的例子中,我的应用程序使用的是自托管 SignalR。
我一直在开发 Web 服务 (C# WebAPI2),因此可以简单地使用 SignalR 发送消息,然后将消息抄本存储在 TSQL 数据库中。但是,在 class 库中移动 SignalR 集线器后,我现在似乎无法访问它们。我开发了一个非常简单的控制台应用程序来与 Web 服务进行通信,但我收到了一个奇怪的异常。
这是抛出的异常:
"StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\n Transfer-Encoding: chunked\r\n X-SourceFiles: =?UTF-8?B?QzpcRGV2ZWxvcG1lbnRcU291cmNlQ29kZVxTVVBTZXJ2aWNlXFNVUC5TZXJ2aWNlXHNpZ25hbHJcbmVnb3RpYXRl?=\r\n Cache-Control: private\r\n Date: Wed, 11 Mar 2015 10:50:18 GMT\r\n Server: Microsoft-IIS/8.0\r\n X-AspNet-Version: 4.0.30319\r\n X-Powered-By: ASP.NET\r\n Content-Type: text/html; charset=utf-8\r\n}"
An unhandled exception of type 'System.AggregateException' occurred in SignalR Client Connection.exe
Owin 启动文件位于 Web 服务 App_Start 文件夹中,如下所示:
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using Microsoft.AspNet.SignalR;
[assembly: OwinStartup(typeof(Service.App_Start.Startup))]
namespace Service.App_Start
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/signalr", map =>
{
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true,
EnableJSONP = true
};
map.RunSignalR(hubConfiguration);
});
}
}
}
非常感谢。
我不确定你的情况的细节,但对我来说,我发现我收到了 System.AggregationException:
System.AggregateException was unhandled
HResult=-2146233088
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at Client.CommunicationHandler.AddMessage(String method, String args, String serverUri, String hubName) in c:\Workspace\EnvisionRealTimeRemoteOps\CodeProjectSelfHostedBroadcastServiceSignalRSample\Client\CommunicationHandler.cs:line 24
at Client.Program.Main(String[] args) in c:\Workspace\EnvisionRealTimeRemoteOps\CodeProjectSelfHostedBroadcastServiceSignalRSample\Client\Program.cs:line 15
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.Http.HttpRequestException
HResult=-2146233088
Message=An error occurred while sending the request.
InnerException: System.Net.WebException
HResult=-2146233079
Message=Unable to connect to the remote server
Source=System
StackTrace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=No connection could be made because the target machine actively refused it 127.0.0.1:8083
Source=System
ErrorCode=10061
NativeErrorCode=10061
StackTrace:
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
InnerException:
直到我添加了对以下内容的调用:
WebApp.Start("http://localhost:8083"); // Put your desired URL in...
请注意,在我的例子中,我的应用程序使用的是自托管 SignalR。