HttpModules - Webservices

B

Bruce Hodge

Hi,

We have a couple of clients who are having trouble connecting to .Net
webservices, (they're coming from PHP and VFP). We were looking to provide
a diagonostic tool that displayed the soap message submitted so that if the
call failed they could compare their SoapMessage with the ones we generate
in .Net.

Thought the solution was an HttpModule hooked into begin request, but after
approx 10 requests it hangs the webservice/aspnet service, any thoughts?
Code below.

(The HttpRequests are stored in Typed Dataset, stored on the Application
object so that they can be accessed from webpages.)


public void OnBeginRequest(Object s, EventArgs e)
{
try
{
// Cast the Object to the HttpApplication variable.
HttpApplication app = (HttpApplication)s;

HttpRequest newRequest = app.Request;

string servers = this.ServicesToMonitor();
int posn =
servers.ToLower().IndexOf(this.GetServiceName(newRequest).ToLower());

if (posn > -1)
this.AddFromHttpRequest(this.RequestHistory, newRequest);

}

catch (Exception ex)
{
//Custom error logging code
}

}

private void AddFromHttpRequest(Mars.Schema.HttpRequests history,
HttpRequest request)
{
try
{
HttpContext.Current.Application.Lock();

byte [] byteArray = new byte[request.ContentLength];

request.InputStream.Read(byteArray, 0, request.ContentLength);

// Must reset the Input Stream position or the whole process fails.
request.InputStream.Position = 0;

Mars.Schema.HttpRequests.RequestsRow row =
this.RequestHistory.Requests.AddRequestsRow(


request.RawUrl,
request.HttpMethod,
request.ContentType,
request.ContentLength,
Encoding.ASCII.GetString(byteArray, 0, request.ContentLength),
DateTime.Now,
this.GetServiceName(request),
this.SOAPAction(request),
request.ServerVariables["REMOTE_ADDR"]);

foreach (string s in request.Headers.AllKeys)
this.RequestHistory.HttpHeaders.AddHttpHeadersRow(row.RequestID,
s, request.Headers);

while (this.RequestHistory.Requests.Count > this.HistorySize)
{
this.RequestHistory.Requests[0].Delete();
}

this.RequestHistory.AcceptChanges();

HttpContext.Current.Application.UnLock();

}

catch (Exception ex)
{

#region Catch Block

#endregion

HttpContext.Current.Application.UnLock();

}

}
 
S

Scott Allen

Bruce:

The Application.Lock would make me nervous. It does look as if you
have an Unlock at the right places, but you might consider using a
finally clause. I'd

When the application blocks can you break in with the debugger and
look at call stacks for all the threads? That might show you how the
application became deadlocked.
 
B

Bruce Hodge

Hi Scott,

When the service hangs I can't break in, but I do have some information from
before it hangs. Also when it does hang the aspnet_wp.exe goes to 95+ CPU
processor time, the memory usage remains static at 82,052K.

On the threads it appears that threads are left running not attached to a
piece of code, I don't know enough on threading to understand this (it
looks like a pool for the aspnet_wp.exe process), basically after a dozen or
so requests have been made the thread window has the following entries:

ID, Name, Location, Priority, Suspend
4740, <No Name>, , Normal, 0
3724, <No Name>, , Normal, 0
4608, <No Name>, , , 0
4264, <No Name>, , Mars.Utils.HttpRequestViewer.OnBeginRequest, Normal, 0

The only way to clear the problem is to End the aspnet_wp.exe process.

To see whether there were thread issues on the Application object I tried
saving the Dataset on the Cache and to a Static variable, it made no
difference.



Regards Bruce H


Scott Allen said:
Bruce:

The Application.Lock would make me nervous. It does look as if you
have an Unlock at the right places, but you might consider using a
finally clause. I'd

When the application blocks can you break in with the debugger and
look at call stacks for all the threads? That might show you how the
application became deadlocked.

--
Scott
http://www.OdeToCode.com/blogs/scott/


Hi,

We have a couple of clients who are having trouble connecting to .Net
webservices, (they're coming from PHP and VFP). We were looking to
provide
a diagonostic tool that displayed the soap message submitted so that if
the
call failed they could compare their SoapMessage with the ones we generate
in .Net.

Thought the solution was an HttpModule hooked into begin request, but
after
approx 10 requests it hangs the webservice/aspnet service, any thoughts?
Code below.

(The HttpRequests are stored in Typed Dataset, stored on the Application
object so that they can be accessed from webpages.)


public void OnBeginRequest(Object s, EventArgs e)
{
try
{
// Cast the Object to the HttpApplication variable.
HttpApplication app = (HttpApplication)s;

HttpRequest newRequest = app.Request;

string servers = this.ServicesToMonitor();
int posn =
servers.ToLower().IndexOf(this.GetServiceName(newRequest).ToLower());

if (posn > -1)
this.AddFromHttpRequest(this.RequestHistory, newRequest);

}

catch (Exception ex)
{
//Custom error logging code
}

}

private void AddFromHttpRequest(Mars.Schema.HttpRequests history,
HttpRequest request)
{
try
{
HttpContext.Current.Application.Lock();

byte [] byteArray = new byte[request.ContentLength];

request.InputStream.Read(byteArray, 0, request.ContentLength);

// Must reset the Input Stream position or the whole process
fails.
request.InputStream.Position = 0;

Mars.Schema.HttpRequests.RequestsRow row =
this.RequestHistory.Requests.AddRequestsRow(


request.RawUrl,
request.HttpMethod,
request.ContentType,
request.ContentLength,
Encoding.ASCII.GetString(byteArray, 0, request.ContentLength),
DateTime.Now,
this.GetServiceName(request),
this.SOAPAction(request),
request.ServerVariables["REMOTE_ADDR"]);

foreach (string s in request.Headers.AllKeys)

this.RequestHistory.HttpHeaders.AddHttpHeadersRow(row.RequestID,
s, request.Headers);

while (this.RequestHistory.Requests.Count > this.HistorySize)
{
this.RequestHistory.Requests[0].Delete();
}

this.RequestHistory.AcceptChanges();

HttpContext.Current.Application.UnLock();

}

catch (Exception ex)
{

#region Catch Block

#endregion

HttpContext.Current.Application.UnLock();

}

}

 
B

Bruce Hodge

Hi Scott,

Yes I've used fiddler for a while and it's very useful. It won't provide
the "total" solution we are looking for and I've not found a way to attach
it to the webservice request, is that possible?

Regards

Bruce H


Scott Allen said:
Bruce:

Also wanted to point out you might consider a tool look Fiddler to
eyeball the request/response from a client machine and see if there
are obvious differences.

http://www.fiddlertool.com/fiddler/

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/


Hi,

We have a couple of clients who are having trouble connecting to .Net
webservices, (they're coming from PHP and VFP). We were looking to
provide
a diagonostic tool that displayed the soap message submitted so that if
the
call failed they could compare their SoapMessage with the ones we generate
in .Net.

Thought the solution was an HttpModule hooked into begin request, but
after
approx 10 requests it hangs the webservice/aspnet service, any thoughts?
Code below.

(The HttpRequests are stored in Typed Dataset, stored on the Application
object so that they can be accessed from webpages.)


public void OnBeginRequest(Object s, EventArgs e)
{
try
{
// Cast the Object to the HttpApplication variable.
HttpApplication app = (HttpApplication)s;

HttpRequest newRequest = app.Request;

string servers = this.ServicesToMonitor();
int posn =
servers.ToLower().IndexOf(this.GetServiceName(newRequest).ToLower());

if (posn > -1)
this.AddFromHttpRequest(this.RequestHistory, newRequest);

}

catch (Exception ex)
{
//Custom error logging code
}

}

private void AddFromHttpRequest(Mars.Schema.HttpRequests history,
HttpRequest request)
{
try
{
HttpContext.Current.Application.Lock();

byte [] byteArray = new byte[request.ContentLength];

request.InputStream.Read(byteArray, 0, request.ContentLength);

// Must reset the Input Stream position or the whole process
fails.
request.InputStream.Position = 0;

Mars.Schema.HttpRequests.RequestsRow row =
this.RequestHistory.Requests.AddRequestsRow(


request.RawUrl,
request.HttpMethod,
request.ContentType,
request.ContentLength,
Encoding.ASCII.GetString(byteArray, 0, request.ContentLength),
DateTime.Now,
this.GetServiceName(request),
this.SOAPAction(request),
request.ServerVariables["REMOTE_ADDR"]);

foreach (string s in request.Headers.AllKeys)

this.RequestHistory.HttpHeaders.AddHttpHeadersRow(row.RequestID,
s, request.Headers);

while (this.RequestHistory.Requests.Count > this.HistorySize)
{
this.RequestHistory.Requests[0].Delete();
}

this.RequestHistory.AcceptChanges();

HttpContext.Current.Application.UnLock();

}

catch (Exception ex)
{

#region Catch Block

#endregion

HttpContext.Current.Application.UnLock();

}

}

 
S

Scott Allen

For .NET clients calling web services you might try:

GlobalProxySelection.Select = new WebProxy("127.0.0.1", 8888);

and that should pump packets through Fiddler. To trace calls from PHP,
VFP - I don't know. I'd imagine there would be someway to specify a
proxy server for the calls but I don't know what that would be.

--
Scott
http://www.OdeToCode.com/blogs/scott/


Hi Scott,

Yes I've used fiddler for a while and it's very useful. It won't provide
the "total" solution we are looking for and I've not found a way to attach
it to the webservice request, is that possible?

Regards

Bruce H


Scott Allen said:
Bruce:

Also wanted to point out you might consider a tool look Fiddler to
eyeball the request/response from a client machine and see if there
are obvious differences.

http://www.fiddlertool.com/fiddler/

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/


Hi,

We have a couple of clients who are having trouble connecting to .Net
webservices, (they're coming from PHP and VFP). We were looking to
provide
a diagonostic tool that displayed the soap message submitted so that if
the
call failed they could compare their SoapMessage with the ones we generate
in .Net.

Thought the solution was an HttpModule hooked into begin request, but
after
approx 10 requests it hangs the webservice/aspnet service, any thoughts?
Code below.

(The HttpRequests are stored in Typed Dataset, stored on the Application
object so that they can be accessed from webpages.)


public void OnBeginRequest(Object s, EventArgs e)
{
try
{
// Cast the Object to the HttpApplication variable.
HttpApplication app = (HttpApplication)s;

HttpRequest newRequest = app.Request;

string servers = this.ServicesToMonitor();
int posn =
servers.ToLower().IndexOf(this.GetServiceName(newRequest).ToLower());

if (posn > -1)
this.AddFromHttpRequest(this.RequestHistory, newRequest);

}

catch (Exception ex)
{
//Custom error logging code
}

}

private void AddFromHttpRequest(Mars.Schema.HttpRequests history,
HttpRequest request)
{
try
{
HttpContext.Current.Application.Lock();

byte [] byteArray = new byte[request.ContentLength];

request.InputStream.Read(byteArray, 0, request.ContentLength);

// Must reset the Input Stream position or the whole process
fails.
request.InputStream.Position = 0;

Mars.Schema.HttpRequests.RequestsRow row =
this.RequestHistory.Requests.AddRequestsRow(


request.RawUrl,
request.HttpMethod,
request.ContentType,
request.ContentLength,
Encoding.ASCII.GetString(byteArray, 0, request.ContentLength),
DateTime.Now,
this.GetServiceName(request),
this.SOAPAction(request),
request.ServerVariables["REMOTE_ADDR"]);

foreach (string s in request.Headers.AllKeys)

this.RequestHistory.HttpHeaders.AddHttpHeadersRow(row.RequestID,
s, request.Headers);

while (this.RequestHistory.Requests.Count > this.HistorySize)
{
this.RequestHistory.Requests[0].Delete();
}

this.RequestHistory.AcceptChanges();

HttpContext.Current.Application.UnLock();

}

catch (Exception ex)
{

#region Catch Block

#endregion

HttpContext.Current.Application.UnLock();

}

}


 
S

Scott Allen

Hi Buck:

These problems can be pretty tough to debug. One approach I've used is
the dump file approach with WinDbg [1], but this can be a steep
learning curve if you haven't used the tools or done any debugging
with a native debugger.

Just to make sure the problem isn't a thread deadlock, you could
replace Application.Lock with Ian's TimedLock [2] and see if there are
error messages about locks timing out.

What is the HistorySize? Could the Delete operation on the DataTable
be sucking up lots of CPU?


[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/dbgrm.asp
[2] http://www.interact-sw.co.uk/iangblog/2004/03/23/locking

--
Scott
http://www.OdeToCode.com/blogs/scott/


Hi Scott,

When the service hangs I can't break in, but I do have some information from
before it hangs. Also when it does hang the aspnet_wp.exe goes to 95+ CPU
processor time, the memory usage remains static at 82,052K.

On the threads it appears that threads are left running not attached to a
piece of code, I don't know enough on threading to understand this (it
looks like a pool for the aspnet_wp.exe process), basically after a dozen or
so requests have been made the thread window has the following entries:

ID, Name, Location, Priority, Suspend
4740, <No Name>, , Normal, 0
3724, <No Name>, , Normal, 0
4608, <No Name>, , , 0
4264, <No Name>, , Mars.Utils.HttpRequestViewer.OnBeginRequest, Normal, 0

The only way to clear the problem is to End the aspnet_wp.exe process.

To see whether there were thread issues on the Application object I tried
saving the Dataset on the Cache and to a Static variable, it made no
difference.



Regards Bruce H


Scott Allen said:
Bruce:

The Application.Lock would make me nervous. It does look as if you
have an Unlock at the right places, but you might consider using a
finally clause. I'd

When the application blocks can you break in with the debugger and
look at call stacks for all the threads? That might show you how the
application became deadlocked.

--
Scott
http://www.OdeToCode.com/blogs/scott/


Hi,

We have a couple of clients who are having trouble connecting to .Net
webservices, (they're coming from PHP and VFP). We were looking to
provide
a diagonostic tool that displayed the soap message submitted so that if
the
call failed they could compare their SoapMessage with the ones we generate
in .Net.

Thought the solution was an HttpModule hooked into begin request, but
after
approx 10 requests it hangs the webservice/aspnet service, any thoughts?
Code below.

(The HttpRequests are stored in Typed Dataset, stored on the Application
object so that they can be accessed from webpages.)


public void OnBeginRequest(Object s, EventArgs e)
{
try
{
// Cast the Object to the HttpApplication variable.
HttpApplication app = (HttpApplication)s;

HttpRequest newRequest = app.Request;

string servers = this.ServicesToMonitor();
int posn =
servers.ToLower().IndexOf(this.GetServiceName(newRequest).ToLower());

if (posn > -1)
this.AddFromHttpRequest(this.RequestHistory, newRequest);

}

catch (Exception ex)
{
//Custom error logging code
}

}

private void AddFromHttpRequest(Mars.Schema.HttpRequests history,
HttpRequest request)
{
try
{
HttpContext.Current.Application.Lock();

byte [] byteArray = new byte[request.ContentLength];

request.InputStream.Read(byteArray, 0, request.ContentLength);

// Must reset the Input Stream position or the whole process
fails.
request.InputStream.Position = 0;

Mars.Schema.HttpRequests.RequestsRow row =
this.RequestHistory.Requests.AddRequestsRow(


request.RawUrl,
request.HttpMethod,
request.ContentType,
request.ContentLength,
Encoding.ASCII.GetString(byteArray, 0, request.ContentLength),
DateTime.Now,
this.GetServiceName(request),
this.SOAPAction(request),
request.ServerVariables["REMOTE_ADDR"]);

foreach (string s in request.Headers.AllKeys)

this.RequestHistory.HttpHeaders.AddHttpHeadersRow(row.RequestID,
s, request.Headers);

while (this.RequestHistory.Requests.Count > this.HistorySize)
{
this.RequestHistory.Requests[0].Delete();
}

this.RequestHistory.AcceptChanges();

HttpContext.Current.Application.UnLock();

}

catch (Exception ex)
{

#region Catch Block

#endregion

HttpContext.Current.Application.UnLock();

}

}


 
B

Bruce Hodge

Hi Scott,

I'll work my way through that.

The history size just limites the record to the most recent 20 records and
the headers are in a seperate table, 2 tables in the XSD in all. So there
shouldn't be any problems there unless the DataSet object has threading
issues I'm not aware off?

Regards

Bruce H
 
S

Scott Allen

Sorry, that should have been "Bruce" not "Buck". Don't know where that
came from, apologies.

The DataSet shouldn't have problems with differrent threads adding /
removing rows - as long as it's not concurrent access, which it looks
like you've taken care of.
 
B

Bruce Hodge

Hi Scott,

through a process of trial an error I've narrowed the problem down to the
Dataset, the only issue now is whether to work around or find the problem,
anyway the weekend is here so a problem for Monday.

Regards

Bruce H
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top