multiple users accessing wcf, stalls service
we currently have this setup:
1) a web site that fronts functionality to user, one of its modules connect to a separate web service (WCF) as reference.
2) an internal web service only visible within the network that provides a separate functionality to the public website. it render and return some data and rdlc reports as byte array.
When I tried running the web service's application pool under Network System, the website failed to access it. But when I set the web service to Local System it works.
The only issue left is that whenever more users tr开发者_StackOverflowy to access this web service from the website, somehow, the web service stalls and a pool refresh is required to make it running again. I've checked the settings of the IIS for the web service and connections are set to unlimited.
Help!
As I said in my comment, for any serious work I would typically recommend against using IIS as an application host. It has several drawbacks (it dictates the service address, it has to deal with app pools and recycling those etc.)
Instead, I usually do my production services in a self-hosting manner, e.g. inside a Windows NT service. This gives me a lot more flexibility: I'm in full control of all aspects, including addresses, and I can start/stop services at will, and I'm not at the mercy of app pools being recycled.
Basically, what you need to do is create an instance of ServiceHost
from the WCF runtime, and give it your service class to host, and optionally one (or multiple) base addresses where your service is exposing endpoints at.
ServiceHost svcHost = new ServiceHost(typeof(MyWCFService));
// optionally set additional properties here, if needed
svcHost.Open(); // now, the host is open and accepting
When you want to stop listening to requests, you just call svcHost.Close()
and your service host is gone.
When you package this into a NT service, typically you do the setup and .Open()
of the service host in the OnStart
method, and you handle the svcHost.Close()
in the OnStop
method of the NT Service.
This app that contains the ServiceHost
doesn't have to be a NT Service - especially for testing, it's always very easy to put your ServiceHost into a console app, start it up and thus bring your WCF service to life, test/debug/enhance, and then just close the console app again. Much easier than mucking around with IIS, virtual directories and stuff like that, in my opinion.
See:
- How To: Host a WCF Service in a managed application
- Hosting WCF Services (page 3 - self-hosting)
精彩评论