Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.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# 如何使用部署的服务创建SignalR客户端?_C#_Azure_Signals_Signalr Hub - Fatal编程技术网

C# 如何使用部署的服务创建SignalR客户端?

C# 如何使用部署的服务创建SignalR客户端?,c#,azure,signals,signalr-hub,C#,Azure,Signals,Signalr Hub,我有这个信号机代码 <div class="container"> <input type="text" id="username" /> <input type="text" id="tags" /> <input type="button" id="sendmessage" value="Register" /> <input type="hidden" id="displayname" /> <ul id="discussi

我有这个信号机代码

<div class="container">
<input type="text" id="username" />
<input type="text" id="tags" />
<input type="button" id="sendmessage" value="Register" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div>
@section scripts {
<!--Script references. -->
<!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
<!--Reference the SignalR library. -->
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
<!--SignalR script to update the chat page and send messages.-->
<script>
    $(function () {
        // Reference the auto-generated proxy for the hub.
        var chat = $.connection.notificationHub;
        // Create a function that the hub can call back to display messages.
        chat.client.addNewMessageToPage = function (name, message) {
            // Add the message to the page.
            $('#discussion').append('<li><strong>' + htmlEncode(name)
                + '</strong>: ' + htmlEncode(message) + '</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.
        $('#username').focus();
        // Start the connection.
        $.connection.hub.start().done(function () {
            $('#sendmessage').click(function () {
                // Call the Send method on the hub.
                chat.server.register($('#username').val(),         $('#tags').val());
                // Clear text box and reset focus for next comment.
                //$('#message').val('').focus();
            });
        });
    });
    // This optional function html-encodes messages for display in the page.
    function htmlEncode(value) {
        var encodedValue = $('<div />').text(value).html();
        return encodedValue;
    }
</script>

我必须使用addNewMessageToPage方法,但无法理解plz帮助

我认为您的代码来自:

在这个例子中,他们调用
Send
方法

public void Send(string name, string message)
{
    // Call the broadcastMessage method to update clients.
    Clients.All.broadcastMessage(name, message);
}
使用
chat.server.send($('#displayname').val(),$('#message').val())

如果要调用
addNewMessageToPage

您必须使用:

chat.server.addNewMessageToPage($('#displayname').val(),$('#message').val())

您的中心功能应该是:

public void AddNewMessageToPage(string name, string message)
{ 
//Some stuff here
}   

问题已经解决,URL不正确,应该是这样的(“var hubUrl=”)。如果您尝试其他问题,您可以使用
hubConnection.TraceLevel=TraceLevels.All;hubConnection.TraceWriter=控制台.Out
public void AddNewMessageToPage(string name, string message)
{ 
//Some stuff here
}