Hello, Kunal!
line "result.AsyncWaitHandle.WaitOne();"
blocks in ProcessRequest method thus breaking the async execution.
Try to comment that line an repeat your tests.
You wrote on 21 Dec 2006 14:41:15 -0800:
K> Hi Friends,
K> I'm trying to host a webservice that will receive/process multiple
K> client requests simultaneously. For this purpose, I wrote the
K> following
K> code, but it does not seem to be handling more than two at a time. I
K> put in a few console prints and have also attached the output. Here
K> it
K> goes -
K> public void serverStart() {
K> HttpListener _listener = new HttpListener();
K> _listener.Prefixes.Add(.......);
K> _listener.Start();
K> while (true)
K> ProcessRequest();
K> }
K> public void ProcessRequest()
K> {
K> Console.WriteLine("PR " + ++count); //count initialized to 0 in
K> beginning
K> IAsyncResult result = _listener.BeginGetContext(new AsyncCallback
K> ListenerCallback),this._listener);
K> result.AsyncWaitHandle.WaitOne();
K> }
K> protected void ListenerCallback(IAsyncResult result)
K> {
K> if (this._listener == null) return;
K> HttpListenerContext context =
K> this._listener.EndGetContext(result);
K> Console.WriteLine("LC " + count);
K> this.ProcessRequest2(context);
K> }
K> public void ProcessRequest2(HttpListenerContext ctx)
K> {
K> Console.WriteLine("PR2 " + count);
K> string str = ctx.Request.HttpMethod;
K> HttpListenerWorkerRequest workerRequest =
K> new HttpListenerWorkerRequest(ctx,_virtualDir, _physicalDir,
K> _logCallback, _pxeb);
K> HttpRuntime.ProcessRequest(workerRequest);
K> }
K> The output this gives me looks like this -
K> PR 1
K> PR 2
K> LC 2
K> PR2 2
K> LC 2
K> PR2 3
K> PR 3
K> LC 3
K> PR2 4
K> PR 4
K> LC 4
K> PR2 5
K> PR 5
K> PR 6
K> LC 6
K> PR2 6
K> LC 6
K> PR2 7
K> PR 7
K> PR 8
K> LC 8
K> PR2 8
K> PR 9
K> LC 9
K> PR2 9
K> LC 9
K> Can someone point out what's happening ? The Microsoft documentation
K> does not say anything about the no. of connections this model can
K> handle or has a limit to. Any developers who have used this may
K> please
K> enlighten me !
K> Thanks and Regards,
K> Kunal
With best regards, Vadym Stetsyak.
Blog:
http://vadmyst.blogspot.com