У меня есть этот код SignalR.Как создать клиент SignalR с развернутым сервисом?
<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>
}
Этот код развертывается как облако лазурного службы.
Мне нужно создать клиент для того же.
То, что я делал на данный момент.
public class Program : Hub
{
ClientEntry objClient = new ClientEntry();
string userName = "test";
string tags = "swe;India;xyz";
public static void Main(string[] args)
{
//Program prg = new Program();
//prg.ConnectToHub();
}
public void ConnectToHub()
{
var hubUrl = "http://test.cloudapp.net/Signalr/hubs/";
var hubConnection = new HubConnection(hubUrl);
var chatHubProxy = hubConnection.CreateHubProxy("TestHub");
hubConnection.Start();
}
public void addNewMessageToPage(string name, string message)
{ }
}
я должен потреблять addNewMessageToPage метод, но не в состоянии понять, плз помочь
Проблема была решена, URL неверен Это должно быть как ("var hubUrl =" http://test.cloudapp.net/Signalr "). – Sudhir
Если вы экспериментируете с другими проблемами, вы можете включить трассировку SignalR с помощью 'hubConnection.TraceLevel = TraceLevels.All; hubConnection.TraceWriter = Console.Out; ' –