有没有办法阻止SignalR服务器?我有自己托管的SignalR服务器作为Windows服务,但我找不到任何方法来停止服务器/服务.
我试过这个但它不起作用 - 服务器一直在监听并阻止服务停止.
或者,如何完全停止服务,强制SignalR关闭?
[编辑]:
大多数来源我不能分享(版权/安全)但我会尽我所能:
SignalR服务器初始化
Task signalRTask = null;
IDisposable SignalR;
#region SignalR server init
// Kreiraj SignalR server
try
{
cancelTokenSrc = new CancellationTokenSource();
signalRTask = Task.Factory.StartNew(RunSignalR, TaskCreationOptions.LongRunning, cancelTokenSrc.Token);
logfile.Info("Starting notifications pool thread...");
//Console.WriteLine(DateTime.Now.ToString("dd.MM.yyyy. HH:mm:ss ") + "Starting notifications pool thread...");
senderThread = new Thread(delegate()
{
sender.poolEvents();
});
senderThread.Start();
}
catch (Exception ex)
{
// greška u startanju SignalR servera
ServiceEngine.logfile.Info("Error starting SignalR on " + signalr_bind + " with error:" + ex.ToString());
//Console.WriteLine(DateTime.Now.ToString("dd.MM.yyyy. …
Run Code Online (Sandbox Code Playgroud) 我有SignalR服务器作为类库项目,我在控制台应用程序中引用它(以模拟Windows服务)
这是SignalR的代码
public void Start()
{
try
{
string url = @"http://*:8081";
using (WebApp.Start<Startup>(url))
{
Logger.Info(string.Format("Server running at {0}", url));
}
}
catch (Exception ex)
{
Logger.Exception(ex, "Signalr start");
}
Run = true;
Logger.Info("Starting Worker");
workerThread = new Thread(() =>
{
Worker();
});
workerThread.Start();
}
Run Code Online (Sandbox Code Playgroud)
这是Startup类
public class Startup
{
Microsoft.AspNet.SignalR.HubConfiguration hubconfiguration = null;
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
hubconfiguration = new HubConfiguration();
hubconfiguration.EnableDetailedErrors = true;
app.MapSignalR(hubconfiguration);
}
}
Run Code Online (Sandbox Code Playgroud)
所以,它在一个线程中,而工作者在另一个线程中.这似乎很好,因为我在其他工作的项目中做到了.工作线程没有问题,它只是空循环,与服务器无关.
问题是服务器似乎"停止" - 当我看到Netstat时,没有人在监听端口8081.没有例外,它只是默默地失败.
我在实际运行此服务器的控制台项目中引用了Owin.Cors(和Owin.Host.HttpListener),但正如我所说,服务器只是停止.
当我尝试连接时,客户端说"连接被主动拒绝",而Putty(telnet)也说"无法连接".
问题出在哪儿?简而言之,我有带有SignalR服务器的类库,在Console项目中引用它运行它,但服务器不会工作.
[编辑]
还有启动服务的Console应用程序代码
static …
Run Code Online (Sandbox Code Playgroud) 如何添加 cookie 以HttpClient
用于注入服务(示例)?我创建了一些服务ApiService
,并且该服务已HttpClient
像CatalogService
教程中一样注入。问题是,为了与外部 API 通信,我的服务必须有一个令牌,该令牌之前由另一个名为usingHttpClient
的 API 接收。因此,当在前端 Web 应用程序中完成登录时:IdentityService
LoginService
if (!string.IsNullOrEmpty(user.Token)) {
ClaimsPrincipal principal = ValidateToken(user.Token);
if (principal != null) {
AuthenticationProperties p = new AuthenticationProperties();
p.ExpiresUtc = DateTime.UtcNow.AddDays(7);
p.IsPersistent = Persistant;
p.RedirectUri = Request.Query.ContainsKey("ReturnUrl") ? Request.Query["ReturnUrl"].ToString() : "";
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, p);
// those cookies are lost when ApiController is called - new instance of http client replaces this one
var apiService = HttpContext.RequestServices.GetService(typeof(IApiService));
var …
Run Code Online (Sandbox Code Playgroud) 我在网上搜索了所有内容,但没有找到简单的解决方案。我正在使用带有“静态”数据源的jQuery DataTables(一个var
使用SignalR填充数据,然后再构建DataTable)。现在,当此数据集发生更改时,我想使用此数据集更新表。理想情况下,这将是简单的“刷新”,即从指定的源重新加载数据。这是我的HTML
<table class="table table-hover table-condensed table-responsive" id="tableAccounts">
<thead>
<tr>
<th data-localize="_A_C">_A_C</th>
<th data-localize="_Name">_Name</th>
<th data-localize="_Address">_Address</th>
<th data-localize="_City">_City</th>
<th data-localize="_Phone">_Phone</th>
</tr>
</thead>
<tbody></tbody>
Run Code Online (Sandbox Code Playgroud)
这是我的javascript,它最初会加载数据:
tAccounts = $('#tableAccounts').dataTable({
"data": AccountAll,
"bFilter": true,
"pageLength": 100,
"bSearchable": true,
"bInfo": false,
"columns": [
{ "data": "AccountCode" },
{ "data": "Name" },
{ "data": "Address" },
{ "data": "City" },
{ "data": "Phone" }
],
"columnDefs": [
{
"render": function (data, type, row) {
return ("0000" + data.toString(16)).slice(-4);
},
"targets": 0
}, …
Run Code Online (Sandbox Code Playgroud) 这个问题可能被问了十几次,但我找不到任何有用的东西......
JSON数据看起来像这样
{
"aaData": [
[
8120,
"username",
"username@hotmail.com",
"\/",
"CUSTOMER ( SellerName )",
"name",
"<span class=\"label label-danger\">2015-08-05<\/span>",
"<a class=\"btn btn-xs btn-primary manageDevices\" href=\"#\" id=\"manageDevices\" data-customerid=\"8120\" data-toggle=\"modal\">1<\/a>",
"<a id=\"8120\" href=\"http:\/\/cms.*********.com:8081\/manageCustomers?customerId=8120\" class=\"btn btn-xs btn-primary\">View<\/a>",
"YES"
],
....
]
],
"sEcho": "NULL",
"iTotalRecords": 65,
"iTotalDisplayRecords": 65
}
Run Code Online (Sandbox Code Playgroud)
显然,这失败了:
private class OuterUser
{
string id { get; set; }
string username { get; set; }
string line { get; set; }
string reseller { get; set; }
string username2 { get; set; } …
Run Code Online (Sandbox Code Playgroud) c# ×4
signalr ×2
asp.net-core ×1
datatables ×1
javascript ×1
jquery ×1
json ×1
self-hosting ×1
service ×1