我已经使用ASP.Net Webforms开发了一个监视系统。我使用SignalR 2.4.0触发自动刷新功能进行实时数据监视。 SignalR似乎可以在IIS Express上运行,但是当我将其发布到IIS 8.5时,SignalR客户端中心事件不会触发。
这是我的Startup.cs
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
var HubConfiguration = new HubConfiguration();
app.MapSignalR();
}
}
这是我的中心:
[HubName("chartData")]
public class ChartDataHub : Hub , IRequiresSessionState
{
SqlCommand objSQLCMD = new SqlCommand();
DataSet dsResult = new DataSet();
DataTable dtResult = new DataTable();
DataTable dtResult2 = new DataTable();
DataTable dtResult3 = new DataTable();
string strSQL = "";
private readonly static Lazy<ChartData> _instance = new Lazy<ChartData>(() => new ChartData());
public static ChartData Instance
{
get
{
return _instance.Value;
}
}
public readonly System.Timers.Timer _Timer = new System.Timers.Timer();
public ChartDataHub()
{
_Timer.Interval = 10000;
_Timer.Elapsed += TimerCallBack;
_Timer.Start();
}
/// <summary>
/// Timer callback method
/// </summary>
/// <param name="state"></param>
private void TimerCallBack(object sender, System.Timers.ElapsedEventArgs e)
{
GetClients().All.updateTakeInData(UpdateTRTakeInData());
GetClients().All.updateTakeOutData(UpdateTRTakeOutData());
}
//GetTakeInData
private object UpdateTRTakeInData()
{
List<GetTakeInCount> lst = new List<GetTakeInCount>();
using (SqlConnection con = new SqlConnection(oDBMngr.ConnectionString))
{
con.Open();
strSQL = "SELECT Date,TotalPlan,TakeInQty,Order3Qty,DelayedQty FROM vewTRTakeInMonthly";
objSQLCMD = new SqlCommand(strSQL, con);
objSQLCMD.CommandType = CommandType.Text;
SqlDataReader rdr = objSQLCMD.ExecuteReader();
while (rdr.Read())
{
GetTakeInCount rowData = new GetTakeInCount();
rowData.TakeInQuantity = Convert.ToDouble(rdr["TakeInQty"].ToString());
rowData.Date = rdr["Date"].ToString();
rowData.PlanQuantity = rdr["TotalPlan"].ToString();
rowData.AccPlanQty = Convert.ToDouble(rdr["TotalPlan"].ToString());
rowData.OrderQty = Convert.ToDouble(rdr["Order3Qty"].ToString());
rowData.DelayedQty = Convert.ToDouble(rdr["DelayedQty"].ToString());
lst.Add(rowData);
}
return lst;
}
}
//GetTakeOutData
private object UpdateTRTakeOutData()
{
List<GetTakeOutCount> lst = new List<GetTakeOutCount>();
using (SqlConnection con = new SqlConnection(oDBMngr.ConnectionString))
{
con.Open();
strSQL = "SELECT * FROM vewTRTakeOutMonthly";
objSQLCMD = new SqlCommand(strSQL, con);
objSQLCMD.CommandType = CommandType.Text;
SqlDataReader rdr = objSQLCMD.ExecuteReader();
while (rdr.Read())
{
GetTakeOutCount rowData = new GetTakeOutCount();
rowData.Date = rdr["Date"].ToString();
rowData.TakeOutQty = Convert.ToDouble(rdr["TakeOutQty"].ToString());
rowData.PlanQty = Convert.ToDouble(rdr["MonthlyPlan"].ToString());
rowData.DI2Qty = Convert.ToDouble(rdr["DI2Quantity"].ToString());
rowData.CPSStockQty = Convert.ToDouble(rdr["CPSStockQty"].ToString());
lst.Add(rowData);
}
return lst;
}
}
private static dynamic GetClients()
{
return GlobalHost.ConnectionManager.GetHubContext<ChartDataHub>().Clients;
}
}
public class GetTakeInCount
{
public string Date { get; set; }
public double TakeInQuantity { get; set; }
public string PlanQuantity { get; set; }
public double AccPlanQty { get; set; }
public double OrderQty { get; set; }
public double DelayedQty { get; set; }
}
public class GetTakeOutCount
{
public string Date { get; set; }
public double TakeOutQty { get; set; }
public double CPSStockQty { get; set; }
public double DI2Qty { get; set; }
public double PlanQty { get; set; }
}
这是我的JS:
var chartData = $.connection.chartData;
chartData.client.updateTakeOutData = function (data) {
//.........
}
$.connection.hub.logging = true;
$.connection.hub.start();
这是IE中的日志:
[12:25:44 GMT+0800 (Taipei Standard Time)] SignalR: Client subscribed to hub 'chartdata'.
[12:25:44 GMT+0800 (Taipei Standard Time)] SignalR: Negotiating with '/DailyTakeInTakeOutMonitoring/signalr/negotiate?clientProtocol=2.0&connectionData=%5B%7B%22name%22%3A%22chartdata%22%7D%5D'.
[12:25:44 GMT+0800 (Taipei Standard Time)] SignalR: Negotiating with '/DailyTakeInTakeOutMonitoring/signalr/negotiate?clientProtocol=2.0&connectionData=%5B%7B%22name%22%3A%22chartdata%22%7D%5D'.
[12:25:47 GMT+0800 (Taipei Standard Time)] SignalR: serverSentEvents transport starting.
[12:25:47 GMT+0800 (Taipei Standard Time)] SignalR: This browser doesn't support SSE.
[12:25:47 GMT+0800 (Taipei Standard Time)] SignalR: serverSentEvents transport failed to connect. Attempting to fall back.
[12:25:47 GMT+0800 (Taipei Standard Time)] SignalR: foreverFrame transport starting.
[12:25:47 GMT+0800 (Taipei Standard Time)] SignalR: Binding to iframe's load event.
[12:25:48 GMT+0800 (Taipei Standard Time)] SignalR: Iframe transport started.
[12:25:48 GMT+0800 (Taipei Standard Time)] SignalR: foreverFrame transport connected. Initiating start request.
[12:25:52 GMT+0800 (Taipei Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.
[12:25:52 GMT+0800 (Taipei Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
[12:25:52 GMT+0800 (Taipei Standard Time)] SignalR: foreverFrame transport timed out when trying to connect.
它在那里停止并且没有触发任何客户端方法。 我不知道我的代码有什么问题。我需要帮助的人。 预先感谢。