Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';Microsoft.AspNet.signal.Hubs.ClientProxy';不包含';广播信息';_C#_Asp.net_Signalr - Fatal编程技术网

C# ';Microsoft.AspNet.signal.Hubs.ClientProxy';不包含';广播信息';

C# ';Microsoft.AspNet.signal.Hubs.ClientProxy';不包含';广播信息';,c#,asp.net,signalr,C#,Asp.net,Signalr,按照简单聊天中心的说明,我在技术上能够让它启动并运行,并且我没有对说明进行任何修改 但是,应用程序第一次启动时,显示Clients.All.broadcastMessage未正确动态绑定 当客户端执行javascript chat.server.send()时,server send()方法执行三次(请参阅更新)。前两项导致错误: 其他信息:“Microsoft.AspNet.signal.Hubs.ClientProxy” 不包含“broadcastMessage”的定义 第三个按预期执行:客

按照简单聊天中心的说明,我在技术上能够让它启动并运行,并且我没有对说明进行任何修改

但是,应用程序第一次启动时,显示Clients.All.broadcastMessage未正确动态绑定

当客户端执行javascript chat.server.send()时,server send()方法执行三次(请参阅更新)。前两项导致错误:

其他信息:“Microsoft.AspNet.signal.Hubs.ClientProxy” 不包含“broadcastMessage”的定义

第三个按预期执行:客户端从服务器接收广播

客户端代码的后续执行只会在服务器上执行一次Send()方法,而broadcastMessage会按预期执行

我是否未能正确初始化某些内容

更新:服务器代码第一次只执行一次,而不是三次。按下continue(继续)按钮需要两次,然后才能工作。因为代码是被请求的,所以它是

但是

<!DOCTYPE html>
<html>
<head>
    <title>SignalR Simple Chat</title>
    <style type="text/css">
        .container {
            background-color: #99CCFF;
            border: thick solid #808080;
            padding: 20px;
            margin: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <input type="text" id="message" />
        <input type="button" id="sendmessage" value="Send" />
        <input type="hidden" id="displayname" />
        <ul id="discussion">
        </ul>
    </div>
    <!--Script references. -->
    <!--Reference the jQuery library. -->
    <script src="Scripts/jquery-1.6.4.min.js" ></script>
    <!--Reference the SignalR library. -->
    <script src="Scripts/jquery.signalR-2.0.3.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="signalr/hubs"></script>
    <!--Add script to update the page and send messages.--> 
    <script type="text/javascript">
        $(function () {
            // Declare a proxy to reference the hub. 
            var chat = $.connection.chatHub;
            // Create a function that the hub can call to broadcast messages.
            chat.client.broadcastMessage = function (name, message) {
                // Html encode display name and message. 
                var encodedName = $('<div />').text(name).html();
                var encodedMsg = $('<div />').text(message).html();
                // Add the message to the page. 
                $('#discussion').append('<li><strong>' + encodedName
                    + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
            };
            // Get the user name and store it to prepend to messages.
            $('#displayname').val(prompt('Enter your name:', ''));
            // Set initial focus to message input box.  
            $('#message').focus();
            // Start the connection.
            $.connection.hub.start().done(function () {
                $('#sendmessage').click(function () {
                    // Call the Send method on the hub. 
                    chat.server.send($('#displayname').val(), $('#message').val());
                    // Clear text box and reset focus for next comment. 
                    $('#message').val('').focus();
                });
            });
        });
    </script>
</body>
</html>

这似乎是对异常的过度破坏。在本例中,Microsoft.CSharp.RuntimeBinder.RuntimeBinderException显然将优雅地在后台抛出,而不是实际抛出到顶部


解决方案是告诉调试器不要在该异常时中断。

听起来您在客户端调用某些东西太早了,但您必须发布代码。
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRChat
{
    public class ChatHub : Hub
    {
        public void Send(string name, string message)
        {
            // Call the broadcastMessage method to update clients.
            Clients.All.broadcastMessage(name, message);
        }
    }
}