0
我在WPF SignalR服务器SignalR WPF服务器和ASP.NET MVC的问题
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
Closing += (s, e) => ViewModelLocator.Cleanup();
StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:8080");
using (WebApp.Start(options))
{
}
}
}
Hub.cs
[HubName("clientPushHub")]
public class TestHub : Hub
{
public string GetServerTime()
{
return DateTime.UtcNow.ToString();
}
public void Heartbeat()
{
Console.WriteLine("Hub Heartbeat\n");
Clients.All.heartbeat();
}
public Task JoinGroup(string groupId)
{
return Groups.Add(Context.ConnectionId, groupId);
}
public void addHit(string pageId)
{
}
public Task LeaveGroup(string groupId)
{
return Groups.Remove(Context.ConnectionId, groupId);
}
public override Task OnConnected()
{
return (base.OnConnected());
}
}
Startup.cs
public class Startup
{
public void Configuration(IAppBuilder app)
{
PerformanceEngine performanceEngine = new PerformanceEngine(1000);
Task.Factory.StartNew(async() => await performanceEngine.OnPerformanceMonitor());
// map SignalR urls
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true
};
map.RunSignalR(hubConfiguration);
}
);
}
}
在我的ASP。 NET MVC客户端我有 Index.cshtml
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<script type="text/javascript" src="~/signalr/hubs"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/app.js"></script>
<body ng-app="signalRIntegrationApp">
<div ng-controller="ServerTimeController">
<div>
<h3>Time from server (being pushed every 5 seconds):</h3>
<h4>{{currentServerTime}}</h4>
</div>
</div>
</body>
和app.js
(function() {
var app = angular.module("signalRIntegrationApp", []);
app.service('signalRSvc', function ($rootScope) {
var proxy = null;
var initialize = function() {
var connection = $.hubConnection("http://localhost:8080");
proxy = connection.createHubProxy('clientPushHub');
connection.start(function() {
proxy.addHit();
});
proxy.on('serverTime', function (data) {
$rootScope.$emit('serverTime', data);
});
}
return {
initialize: initialize
};
});
app.controller('ServerTimeController', ["$scope", 'signalRSvc', function($scope, signalRSvc) {
var vm = this;
$scope.$on("serverTime", function (e, data) {
$scope.$apply(function() {
vm.currentServerTime = data;
});
});
signalRSvc.initialize();
}]);
})()
错误的客户端是http://localhost:8081在IIS快递
更新: 谈判请求中的错误
什么是错误(HTTP状态码)? – Pawel
@Pawel协商请求期间出错 – amplifier