代码之家  ›  专栏  ›  技术社区  ›  GNewton

类库中的C#SignalR

  •  1
  • GNewton  · 技术社区  · 9 年前

    我一直在开发一个Web服务(C#WebAPI2),因此可以使用SignalR发送消息,然后将消息副本存储在TSQL数据库中。然而,在移动了一个类库中的SignalR集线器之后,我现在似乎无法访问它们。我开发了一个非常简单的控制台应用程序来与Web服务通信,但我遇到了一个奇怪的异常。

    以下是正在引发的异常:

    “StatusCode:500,ReasonPhrase:'内部服务器错误',版本:1.1, 内容:System.Net.Http.StreamContent,标头:\r\n{\r\n 传输编码:分块\r\n X-SourceFiles: =?UTF-8?BQzpcRGV2ZWxvcG1lbnRcU291cmNlQ29kZVxTVVBTZXJ2aWNlXFNVUC5TZXJ2a WNlXHNpZ25hbHJcbmVnb3RpYXRl=\\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内容类型:text/html; charset=utf-8\r\n}“

    发生“System.AggregateException”类型的未处理异常 在SignalR客户端Connection.exe中

    OwinStartup文件位于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 回复  |  直到 9 年前
        1
  •  0
  •   johnnyRose    7 年前

    我不确定您案例中的详细信息,但对我来说,我发现我收到了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...
    

    请注意,在我的情况下,我的应用程序使用的是Self-Hosted SignalR。