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