【发布时间】:2015-12-10 15:01:55
【问题描述】:
我构建了一个处理通知请求的 Web 服务和一个使用 SignalR 接收推送通知的网站。当使用 Visual Studio 在我的机器上运行 web 服务和网站时,这一切都很好,并且任何 web 服务器 VS 用于运行项目。
但是,自从移至运行 IIS 7 的测试服务器后,signalR 不再工作。 webservice和website都在同一个服务器上,webservice在8088端口,webservice在8089端口。
这是我得到的错误
10-12-2015 14:56:26,864 [UK\!kerslaj1][35] ERROR Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - There was an error opening the connection 'http://localhost:8088/'
Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: close
Date: Thu, 10 Dec 2015 14:56:26 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 334
Content-Type: text/html; charset=us-ascii
}
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass2.<Get>b__1(HttpResponseMessage responseMessage)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass42.<RunTask>b__41(Task`1 t)
10-12-2015 14:56:26,866 [UK\!kerslaj1][41] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Connection started
10-12-2015 14:56:26,866 [UK\!kerslaj1][41] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - User: kerslaj1
10-12-2015 14:56:26,866 [UK\!kerslaj1][41] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Added username: UK\!kerslaj1
10-12-2015 14:56:26,867 [UK\!kerslaj1][41] ERROR Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - There was an error notifying using the connection http://localhost:8088/
System.InvalidOperationException: Data cannot be sent because the connection is in the disconnected state. Call start before sending any data.
at Microsoft.AspNet.SignalR.Client.Connection.Send(String data)
at Microsoft.AspNet.SignalR.Client.Hubs.HubProxy.Invoke[TResult,TProgress](String method, Action`1 onProgress, Object[] args)
at Microsoft.AspNet.SignalR.Client.Hubs.HubProxy.Invoke[T](String method, Object[] args)
at Centrica.CE.SEFlex.Common.Notification.SignalRHandler.Notify(EventNotification notification, IEnumerable`1 subscribers, String hubConnection) in c:\Development\TFS\Atlas\SE\DEV\SEFLEX\Build\Common\Centrica.CE.SEFlex.Common\Notification\SignalRHandler.cs:line 66
10-12-2015 14:56:26,868 [UK\!kerslaj1][41] DEBUG SEFlex - Subscriber notified
在我的网站上,SignalR 是这样配置的
public class OwinStartup
{
public void Configuration(IAppBuilder app)
{
var container = new UnityContainer();
container.RegisterType<NotificationHub, NotificationHub>(new ContainerControlledLifetimeManager());
GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => new UnityHubActivator(container));
var idProvider = new PrincipalUserIdProvider();
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider);
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
还有我的布局html页面
@Scripts.Render("~/bundles/signalr")
<script src="/signalr/hubs"></script>
<script>
var notifyProxy = $.connection.notification, // the generated client-side hub proxy
$notificationTable = $('#NotificationTable'),
$notificationTableBody = $notificationTable.find('tbody'),
rowTemplate = '<tr data-symbol="{EventNotificationId}"><td style="text-align:left;width:115px;vertical-align:text-top;"><nobr>{EventDate} : </nobr></td><td><span class="{Class}"><small class="text-uppercase">{ClassLabel}</small></span></td><td style="text-align:left;">{Description}</td></tr>';
function formatNotification(notification) {
return $.extend(notification, {
EventDate: notification.EventTime.substr(0, 10).concat(' ').concat(notification.EventTime.substr(11, 8)),
Description: notification.FriendlyText,
Class: notification.Class
});
}
function init() {
notifyProxy.server.getCurrentNotifications().done(function (notifications) {
$notificationTableBody.empty();
$.each(notifications, function () {
var notification = formatNotification(this);
$notificationTableBody.prepend(rowTemplate.supplant(notification));
});
});
}
// Add a client-side hub method that the server will call
notifyProxy.client.addNotification = function (notification) {
$notificationTableBody.prepend(rowTemplate.supplant(formatNotification(notification)));
};
// Start the connection
$.connection.hub.start().done(init);
</script>
【问题讨论】:
-
这有点像在黑暗中刺伤,但可能是它希望 SignalR 默认在端口 80 上侦听,而您正在端口 8088 上运行您的站点,或者 SignalR仍在监听 80 端口,而您的站点在 8088 上?
标签: c# asp.net-mvc iis signalr