开发者

Asp.net web services and how to reuse a WMI or DB connections?

I have simple asp.net web service, for monitoring and managing about 10 computers, with 4 webMethods and all of this methods are quite simple. In general they look sometning like: (1)make WMI connections to certain machine, (2)do some simple task, (3)return result.

Problem is that WMI connections to remote computers takes about 15s and I offten need to call 2 or 3 methods successively for the same machine.

From what I know, there is new instance 开发者_开发知识库of my service class (public class MonSvr : System.Web.Services.WebService ) created every time webMethod is called.

  • So how can I share WMI or DB connection betwen all instances of my service that I could reuse this connection ?

  • When there all multiple calls to webMethods of my service, does then each instance of web service runs in separate thread ?


You could create a static Dictionary containing the name of the remote machine and the WMI connection. This could then be shared between different calls. You may have issues with multiple threads using the WMI classes at once, so be sure to check all calls are thread safe.


Isn't you want to save the cost of object creation? If it is so then why not use Singleton pattern? and for multi-threaded Singleton you can check http://msdn.microsoft.com/en-us/library/ff650316.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜