我想在控制檯應用程序在南希運行SignalR。SignalR(與自我託管的南希)顯示404協商?clientProtocol = 1.3
當我的瀏覽器$.connection.hub.start()
它得到404 - NotFound
爲//localhost:667/negotiate?clientProtocol=1.3
---- 8 < ----
我(想)在另一個運行南希一個端口上SignalR。南希與剃刀合作。 SignalR返回集線器的JavaScript好吧。
(對不起,下面的代碼量,但我一直沒能進一步降低它。)
(這個問題可以從更早的認識 - 那我就慘標記現在刪除的問題)
客戶端代碼:
<script type="text/javascript" src='/Scripts/jquery-1.6.4.min.js'></script>
<script type="text/javascript" src="/Scripts/jquery.signalR-2.0.0-beta2.js"></script>
<script src="http://localhost:667/signalr/hubs" type="text/javascript"></script>
var chat;
$(function() {
$.connection.hub.url = '//localhost:667';
$.connection.hub.logging = true;
chat = $.connection.chat;
chat.client.addMessage = onAddMessage; // declared but not here
$.connection.hub.start()
.done(function() {
alert($.connection.id);
chat.server.send('Works!');
})
.fail(function (failreason) {
alert(failreason);
});
});
服務器代碼(在控制檯程序運行作爲管理員)
class Program
{
static void Main(string[] args)
{
const string webUrl = "http://localhost:666";
const string signalrUrl = "http://localhost:667";
using (var webHost = new Nancy.Hosting.Self.NancyHost(
new Uri(webUrl)))
{
using (WebApp.Start<Startup>(signalrUrl))
{
webHost.Start();
Console.Write("Press any key");
Console.ReadKey();
webHost.Stop();
}
}
}
}
class Startup
{
public void Configuration(Owin.IAppBuilder app)
{
app.MapHubs(new HubConfiguration() { EnableCrossDomain = true });
app.UseNancy(new ApplicationBootstrapper());
}
}
public class ApplicationBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureConventions(
Nancy.Conventions.NancyConventions nancyConventions)
{
nancyConventions.StaticContentsConventions.Add(
Nancy.Conventions.StaticContentConventionBuilder.AddDirectory(
"Scripts", @"/Scripts")
);
base.ConfigureConventions(nancyConventions);
}
}
public class Chat : Hub
{
public void Send(string message)
{
Clients.All.addMessage(message);
}
}
感謝張貼此代碼回到剛纔的問題。非常明確,並且是示例我有一個SignalR服務器,並且想要爲它添加一個Nancy POST處理程序,這是第一次。僅供參考,我不得不爲Nancy.Owin軟件包添加任何人。 –