类库中的C#SignalR

时间:2015-03-11 10:56:34

标签: c# signalr class-library

我一直在开发Web服务(C#WebAPI2),因此只需使用SignalR发送消息,然后将消息脚本存储在TSQL数据库中。但是,在将类Signal库中的SignalR集线器移动后,我现在似乎无法访问它们。我已经开发了一个非常简单的控制台应用程序来与Web服务进行通信,但是我发现了一个奇怪的例外。

以下是抛出的异常:

  

" StatusCode:500,ReasonPhrase:'内部服务器错误',版本:1.1,   内容:System.Net.Http.StreamContent,Headers:\ r \ n {\ r \ n   Transfer-Encoding:chunked \ r \ n X-SourceFiles:   =?UTF-8 2 B 4 QzpcRGV2ZWxvcG1lbnRcU291cmNlQ29kZVxTVVBTZXJ2aWNlXFNVUC5TZXJ2aWNlXHNpZ25hbHJcbmVnb3RpYXRl?= \ r \ n   缓存控制:私人\ r \ n日期:星期三,2015年3月11日10:50:18 GMT \ r \ n   服务器: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;   字符集= UTF-8 \ r \ N}"

     

未处理的类型' System.AggregateException'发生了   在SignalR Client Connection.exe中

Owin Startup文件放在Web Service 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);
            });
        }
    }
}

非常感谢。

1 个答案:

答案 0 :(得分:0)

我不确定你的案例中的细节,但对我来说,我发现我收到的是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。