难道一个asp.net web服务有类似的应用程序启动和应用程序变量? [英] Does an asp.net webservice have something like application start and application variables?

查看:208
本文介绍了难道一个asp.net web服务有类似的应用程序启动和应用程序变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个web服务,调用的时候,通过TCP连接通知另一个程序。我的问题是在哪里存储开放TCP连接。我理解Web服务的方式,他们开始和每个HTTP请求结束,没有空间应用范围的变量,像打开TCP连接。

I'm developing a webservice that will, when called, notify another program via a tcp connection. My problem is where to store the open tcp connection. The way I understand web services, they start and end with each HTTP Request, with no room for application wide variables, like the open tcp connection.

如果我错了,请大家指正。

Please correct me if I'm wrong.

具体而言,在什么ASMX文件的一部分,或者在它之外,我应该放置在code为侦听传入TCP流量?

Specifically, in what part of the asmx file, or outside of it, should I place the code for listening for incoming tcp traffic?

推荐答案

您可以将TCP连接作为服务类的静态成员,并做出处理实例化一个静态构造函数。

You can place the tcp connection as a static member of the service class and make a static constructor that handles the instantiation.

此将创建web服务处理的第一访问之前的TCP连接,然后,只要宿主进程运行持续的连接。这种做法的唯一缺点是TCP连接的过程宽。如果您在同一过程(不太可能)内承载Web服务的两个实例他们将共享同一个TCP连接。

This will create the tcp connection before the first access of the web service is handled and then persist the connection as long as the hosting process is running. The only drawback with that approach is that the tcp connection is process wide. If you host two instances of the web service within the same process (quite unlikely) they will share the same tcp connection.

这篇关于难道一个asp.net web服务有类似的应用程序启动和应用程序变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆