如何信号-R适合在IIS激活模式?信号、适合、模式、IIS

由网友(你消失的姿态可真帅。)分享简介:我学习信号-R,这是值得在所有时间一直在我的脑海。 I am learning Signal-R, and this is something that has been in my head during all time. 如何信号-R在IIS / ASP.NET生命周期适合?请问集线器住多久(我看他们已经重新...

我学习信号-R,这是值得在所有时间一直在我的脑海。

I am learning Signal-R, and this is something that has been in my head during all time.

如何信号-R在IIS / ASP.NET生命周期适合? 请问集线器住多久(我看他们已经重新连接语义)? 在IIS是否确实prevent具有持久连接一个AppDomain的关机?

这是我的理解是IIS是专门用来处理请求 - 响应方案。请求命中IIS,此发现的AppDomain,激活它,然后将请求传递给它。而空闲的时间,关机的AppDomain之后。如果请求时间过长,超时异常。

It is my understanding that IIS is designed to handle request-response scenarios. A request hits IIS, this finds the AppDomain, activate it, and then pass the request to it. And after an idle time, shutdown the AppDomain. If the request takes too long, a timeout exception is thrown.

现在let's想象,我有通过TCP套接字广播信息的另一个应用程序。我想我的JavaScript客户端实时获得这些信息,所以我创建了一个信号-R的网络应用程序。我可以创建在应用程序启动TCP客户端,但到底是什么保证IIS是不是经过一段时间不活动要关闭整个事情?

Now let´s imagine that I have another application that broadcast information through a TCP socket. I want my javascript clients to get that information in real time, so I create a Signal-R web application. I can create a TCP client on application start, but what does guarantee that IIS is not going to shutdown the whole thing after some time with inactivity?

我可以自我托管在一个窗口服务信号-R的应用程序,但我将不得不使用不同的端口,实现跨域,部署等等许多问题。不过,我担心使用ASP.NET MVC应用程序这一点,因为它看起来对我来说,在摩托车配件驱动轮。

I could self host the Signal-R app in a window service, but then I would have to use a different port, enable cross domain, etc... Many problems for deployment. But, I am concerned about using an ASP.NET MVC application for this, since it looks to me like fitting a driving wheel in a motorbike.

干杯。

推荐答案

SignalR在IIS / ASP.NET生命周期

在SignalR使用Owin: http://owin.org/ 在Owin这里的一个很好的文章:http://msdn.microsoft.com/en-us/magazine/dn451439.aspx SignalR uses Owin: http://owin.org/ A good article on Owin here: http://msdn.microsoft.com/en-us/magazine/dn451439.aspx

集线器对象生存期

从SignalR文档:http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server#transience:

From the SignalR docs: http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server#transience:

您没有实例化集线器类或调用其方法从服务器上自己的code;所有由SignalR集线器管道为你做。 SignalR创建每次需要处理集线器操作时,客户端连接,断开连接,或者发出方法调用到服务器,如时间集线器类的新实例。

You don't instantiate the Hub class or call its methods from your own code on the server; all that is done for you by the SignalR Hubs pipeline. SignalR creates a new instance of your Hub class each time it needs to handle a Hub operation such as when a client connects, disconnects, or makes a method call to the server.

由于集线器类的实例是短暂的,你不能用它从一个方法调用到下一个保持状态。每次服务器从客户机接收一个方法调用,集线器类的新实例处理该消息。为了保持通过多个连接和方法调用的状态,使用其他方法,如数据库,或在集线器类静态变量,或不同类的不脱离集线器派生。如果坚持存储器数据,使用的方法如在集线器类一个静态变量,当应用程序域回收的数据将会丢失。

Because instances of the Hub class are transient, you can't use them to maintain state from one method call to the next. Each time the server receives a method call from a client, a new instance of your Hub class processes the message. To maintain state through multiple connections and method calls, use some other method such as a database, or a static variable on the Hub class, or a different class that does not derive from Hub. If you persist data in memory, using a method such as a static variable on the Hub class, the data will be lost when the app domain recycles.

您的长时间运行的TCP客户端

这是不是与SignalR一个问题。你的TCP客户端可以是关机由IIS:http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx/

This is not a problem with SignalR. Your TCP client can be shutdown by IIS: http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx/

我宁愿做一个Windows服务运行在TCP客户端。 TCP客户机TCP接收广播消息并将消息转发到使用SignalR .NET客户端集线器。

I would rather make the TCP client run in a windows service. The TCP client receives TCP broadcast messages and forwards the messages to the Hub using the SignalR .NET client.

阅读全文

相关推荐

最新文章