2012-04-16 6 views
1

DBからレコードを表示している新しいMVCアプリケーションがあり、新しいレコードを作成できます。 NservicebusのIEventハンドラが完了したときに、SignalRを使用してクライアントに通知しています。NServiceBusでイベントを処理する際に、SignalRがクライアント側の関数を呼び出さない

Index.cshtml

<script src="signalr/hubs" type="text/javascript"></script> 
<script> 
    var myHub; 

    $(function() { 
     myHub = $.connection.userAccountHub; 

     //add handler to handle the nofication 
     myHub.testMsg = function() { 
      alert("I would really like for this to work"); 
     }; 

     $.connection.hub.start(); 
    }); 
</script> 

UserController.cs

public class UserController : Controller 
    { 
     private readonly IBus _bus;  


public ActionResult Index() 
     { 
      return View(getalldata()); 
     } 


[HttpPost] 
     public ActionResult Create(CreateUserAccountModel user) 
     { 
      if (ModelState.IsValid) 
      { 
       _bus.Send(new CreateUserAccountCommand 
       { 
        FirstName = user.FirstName, 
        LastName = user.LastName, 
        NetworkLogin = user.NetworkLogin 
       }); 

       return RedirectToAction("Index"); 
      } 

      return View(user); 
     } 

UserAccountHub

public class UserAccountHub : Hub 
    { 

    } 

UserAccountCreatedNotifyEventHandler.cs

public class UserAccountCreatedNotifyEventHandler : IHandleMessages<UserAccountCreatedNotifyEvent> 
    { 
     public void Handle(UserAccountCreatedNotifyEvent message) 
     { 
      IConnectionManager connectionManager = AspNetHost.DependencyResolver.Resolve<IConnectionManager>(); 
      dynamic clients = connectionManager.GetClients<UserAccountHub>(); 

      clients.testMsg(); 
     } 
    } 

は基本的に私はちょうど私のすべてのレコードを表示し、作成ボタンを持つindexアクションに進みます。作成ボタン@Html.ActionLink("Create", "Create", null, null)をクリックし、public ActionResult Create(CreateUserAccountModel user)メソッドを呼び出しました。バスを起動し、インデックスアクションにリダイレクトします。サービスバスはそのことを行い、UserAccountCreatedNotifyEventHandler Handleメソッドが適切にトリガされます。

これは私がいくつかの問題を見るところです。メッセージをブロードキャストできるようにクライアントを取得するための適切なシグナルメソッドを呼び出しますが、クライアントはメッセージを受信しません。.testMsg()

私の短いシグナルでclients.testMsgは期待通りに動作しません。私が知っている限り、私はWeb上で見つけたコード例、および私が持っている他のテストプロジェクトにも従っています。私は愚かな何かをやっていると仮定していますが、それを目標にしていません。

答えて

2

ハンドラでは、ハブへのプロキシを作成し、そのプロキシでメソッドを呼び出す必要があります。プロキシを注入するときは、毎回高価になるので注入してください!

http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-net-client

+0

を試してみてください参照してください。 – Etch

+0

私は同様のパターンを使用していますが、rabbitmqハンドラからは – redsquare

+0

実際に問題の小さな問題を修正したNServicebusの設定に問題が見つかりました。奇妙なことは、私の上記のコードは初めてのことですが、その後はうまくいきません。私は掘り下げて.CreateProxyメソッドを試してみようとしています。 – Etch

0

は私がすることを試してみる

myHub.client.testMsg = function(){....} 

ない

myHub.testMsg = function(){....} 
関連する問題