Я пытаюсь отправить сообщение из консольного приложения в приложение MVC с помощью SignalR, Ниже приводится код:Отправить сообщение с консоли на веб-страницы с помощью SignalR
static void Main(string[] args)
{
string url = "http://localhost:8080";
string line=null;
MyHub obj = new MyHub();
using (WebApp.Start(url))
{
Console.WriteLine("Server running on {0}", url);
Console.ReadLine();
Console.WriteLine("Enter your message:");
line = Console.ReadLine();
obj.Send(line);
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
}
}
public class MyHub : Hub
{
public void Send(string message)
{
Clients.All.addMessage(message);
}
}
и вот как IAM пытается получить сообщение на сайте:
<script type="text/javascript">
$(function() {
//Set the hubs URL for the connection
$.connection.hub.url = "http://localhost:8080/signalr";
// Declare a proxy to reference the hub.
var chat = $.connection.myHub;
// Create a function that the hub can call to broadcast messages.
chat.client.addMessage = function (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>'
+ '</strong>: ' + 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.
});
</script>
дело в том, что РМКО получаю следующее исключение:
Похоже, что я не могу непосредственно создать объект класса Myhub, любую идею о том, как исправить это, помните, что мне нужно отправить сообщение с консоли на веб-страницу. Любые рекомендации ???
Вы видели этот пост: http://stackoverflow.com/questions/11140164/signalr-console-app-example? –
@DavidTansey na Позвольте мне проверить это – moji
это donthelp so much – moji