2013-06-19 172 views
2

我剛剛開始使用SignalR,並且已經能夠向所有連接的客戶端廣播消息而沒有任何問題。我現在想讓我的客戶端(javascript)加入一個組,並只接收該組的消息。在我中心,我有以下方法添加到命名組連接:SignalR HTTP 500當從客戶端調用服務器方法時

public Task JoinGroup(string groupName) 
    { 
     return this.Groups.Add(Context.ConnectionId, groupName); 
    } 

在客戶端,我有以下JS:

 var latLonBounds = new google.maps.LatLngBounds(); 
     var tripIdentifier = '@Model.TripIdentifier'; 
     $(function() { 
      var hub = $.connection.locationHub; 
      hub.client.updateLocation = function (coordinates) { 
        // Implementation omitted 
       }); 

       latLonBounds.extend(position); 
       map.fitBounds(latLonBounds); 
      }; 
      $.connection.hub.logging = true; 
      $.connection.hub.start().done(function() { 
       hub.server.joinGroup(tripIdentifier); 
      }); 
     }); 

當我的頁面加載,在Chrome中,我看到了以下URL在控制檯中的HTTP 500:

http://localhost:49914/signalr/send?transport=serverSentEvents&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAA8OmZGDrRfEaOjaHahkkarwAAAAACAAAAAAAQZgAAAAEAACAAAADM78kCBInmZa7OROdPoXraiugBXLR5Xu3htxYC2JSnSAAAAAAOgAAAAAIAACAAAAAZwnPx6GMKOiw%2FivqQPlSfCb4WNP342YxvGyBpalmjSDAAAADljl1vg%2F7GYtD3R4AA2A9LXEnNZkyQVQjDUrW7ZVbvfPpWz1GCcOn6aw5yrkrWFrhAAAAAyX5otz0Xhx8tuIRgX2Pr1b9ZWFMvoairvqzns1%2FhjN%2BRhDIuAqAfonTbsZDjkdyDAZXzAKQqwTEKhpa5LYBhKg%3D%3D 

在Visual Studio中,我看到下面的堆棧跟蹤:

SignalR exception thrown by Task: System.AggregateException: One or more errors occurred. ---> System.MissingMethodException: No parameterless constructor defined for this object. 
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
    at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
    at System.Activator.CreateInstance(Type type) 
    at Microsoft.AspNet.SignalR.Hubs.DefaultHubActivator.Create(HubDescriptor descriptor) 
    at Microsoft.AspNet.SignalR.Hubs.DefaultHubManager.ResolveHub(String hubName) 
    at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.CreateHub(IRequest request, HubDescriptor descriptor, String connectionId, StateChangeTracker tracker, Boolean throwIfFailedToCreate) 
    at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.OnReceived(IRequest request, String connectionId, String data) 
    at Microsoft.AspNet.SignalR.PersistentConnection.<>c__DisplayClassa.<>c__DisplayClassc.<ProcessRequest>b__7() 
    at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod(Func`1 func) 
    --- End of inner exception stack trace --- 
---> (Inner Exception #0) System.MissingMethodException: No parameterless constructor defined for this object. 
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
    at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
    at System.Activator.CreateInstance(Type type) 
    at Microsoft.AspNet.SignalR.Hubs.DefaultHubActivator.Create(HubDescriptor descriptor) 
    at Microsoft.AspNet.SignalR.Hubs.DefaultHubManager.ResolveHub(String hubName) 
    at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.CreateHub(IRequest request, HubDescriptor descriptor, String connectionId, StateChangeTracker tracker, Boolean throwIfFailedToCreate) 
    at Microsoft.AspNet.SignalR.Hubs.HubDispatcher.OnReceived(IRequest request, String connectionId, String data) 
    at Microsoft.AspNet.SignalR.PersistentConnection.<>c__DisplayClassa.<>c__DisplayClassc.<ProcessRequest>b__7() 
    at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod(Func`1 func)<--- 

如果我從我的JS中刪除了對hub.server.joinGroup(tripIdentifier);的調用,那麼我沒有得到HTTP 500 /異常,所以看起來這條線是異常的來源。

任何關於我能做些什麼來獲得團體註冊工作的建議將不勝感激。

謝謝!

回答

6

這是告訴你什麼是錯的堆棧的一部分:

---> (Inner Exception #0) System.MissingMethodException: No parameterless constructor defined for this object. 
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
    at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
    at System.Activator.CreateInstance(Type type) 
    at Microsoft.AspNet.SignalR.Hubs.DefaultHubActivator.Create(HubDescriptor descriptor 

基本上那是什麼在說是集線器類沒有參數的構造函數。如果您正在嘗試爲集線器設置依賴注入,則您在使用SignalR註冊依賴關係解析器時會出現問題。如果您提供更多詳細信息,我們也可以幫助您解決問題。

+0

謝謝德魯!這是問題所在。我在我的集​​線器上進行DI操作,並在註冊過程中搞砸了一些東西。碰巧,我已經重構了對集線器中任何依賴關係的需求,但仍然有參數化的構造函數,所以我剛剛擺脫了這一點。 –

相關問題