SignalRでは、サーバーはJSクライアント側の機能を認識していません。クライアントにメッセージを送信するだけで、クライアントは指定された関数が存在する場合はそれを呼び出します。
したがって、500エラー(内部サーバーエラー)が表示されているという事実は、それがクライアントとは何の関係もないと私に信じさせます。
そうは言っても、私は先に進んでC#でコードをテストしましたが、正常に機能しました。また、VB.Netプロジェクトを作成し、最終的に正しく機能するようにしました。
これが私のVB.Netプロジェクトのコードです:
サーバーハブ(MyHub.vb)
Imports Microsoft.AspNet.SignalR.Hubs
<HubName("myHub")>
Public Class MyHub
Inherits Hub
Public Sub sendMsg(ByVal message As String)
Clients.All.invoke_message(Context.ConnectionId, message)
End Sub
Public Sub refresh()
Clients.All.invoke_refresh()
End Sub
End Class
クライアント側コード(default.aspx):
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="default.aspx.vb" Inherits="VBTest._default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="SendMessage">SendMsg</div>
<div id="Refresh">Refresh</div>
</div>
</form>
<script src="Scripts/jquery-1.6.4.js"></script>
<script src="Scripts/jquery.signalR-1.0.0-rc1.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
window.myHub = $.connection.myHub;
myHub.client.invoke_refresh = function () {
// invoked to force the user's page to refresh
document.location.reload(true);
}
myHub.client.invoke_message = function (clientID, message) {
// invoked while broadcasting a message
console.log(clientID + ': ' + message);
};
$.connection.hub.start().done(function () {
$("#SendMessage").click(function () {
window.myHub.server.sendMsg("ELLO");
});
$("#Refresh").click(function () {
window.myHub.server.refresh();
});
});
</script>
</body>
</html>
Global.asax:
Imports System.Web.SessionState
Imports System.Web.Routing
Imports Microsoft.AspNet.SignalR
Public Class Global_asax
Inherits System.Web.HttpApplication
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RouteTable.Routes.MapHubs()
End Sub
End Class
そして私のフォルダ構造のSS:http:
//imgur.com/hpCQC
App_Startコードを削除し、Global.asaxコードに置き換えてください。
私が別の方法で行ったことの1つは、ソース(https://github.com/SignalR/SignalR/tree/release)からすべてのSignalRコードを取得したことです。
お役に立てれば!