Freigeben über


Displaying Http Requests from Self-Hosted WCF Services

 

This is a short one, I promise. A colleague was complaining that NetExt command !whttp was not displaying the active/finished requests on a dump file he was sure it was processing http requests. The truth is that the process was not w3wp.exe (IIS Worker Process) but rather a self-hosted WCF service. The command !whttp relies on System.Web.HttpContext class which is the class used by IIS managed applications to control request and response. Self-hosted WCF Services rely on System.Net.HttpListenerContext class instead. There is no specialized command for that in NetExt but this does not prevent anyone from creating their own query which I show below. If you are interested but have no idea what I am talking about, check this out before you decide it is indeed not something you may be interested in: https://blogs.msdn.com/b/rodneyviana/archive/2015/03/10/getting-started-with-netext.aspx

Command

This is my suggestion of query. Unlike HttpContext, the HttpListenerContext class does not offer a reliable timestamp of the request time, so things like time running and request time are not included. If someone can come up with a way to do this, please let the rest of us know in the comments and I will update the command and give praise to the brave researcher.

The command on a easy to copy-and-paste form:

!wfrom -nospace -nofield -type System.Net.HttpListenerContext where(!m_Request.m_IsDisposed) $addr()," ",$if($stackroot($addr()) == ""," ---",$lpad($split($stackroot($addr()),",",0),4))," ",$rpad($if(m_Response,$enumname(m_Response.m_ResponseState),"Finished"),12),$if(m_Response,$replace($lpad(m_Response.m_NativeResponse.StatusCode,5),"0n"," ")," ---")," ",$rpad($if(m_Request,m_Request.m_HttpMethod,"NA"),8)," ",$isnull(m_request.m_RequestUri.m_String,m_request.m_RawUrl)

Below is the output, the headers are included for clarity purposes, it is not part of the normal output.

  1: !wfrom  -nospace -nofield -type System.Net.HttpListenerContext where(!m_Request.m_IsDisposed) $addr()," ",$if($stackroot($addr()) == ""," ---",$lpad($split($stackroot($addr()),",",0),4))," ",$rpad($if(m_Response,$enumname(m_Response.m_ResponseState),"Finished"),12),$if(m_Response,$replace($lpad(m_Response.m_NativeResponse.StatusCode,5),"0n"," ")," ---")," ",$rpad($if(m_Request,m_Request.m_HttpMethod,"NA"),8)," ",$isnull(m_request.m_RequestUri.m_String,m_request.m_RawUrl)
  2:  
  3: Address        Thread State    Status Verb Url
  4: ==========================================================================================
  5: 00000050D5AEAD58  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  6: 00000050D5B53D20   48 SentHeaders 200 POST https://service.contoso.com/Service/JSONService
  7: 00000050D5B58D58  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  8: 00000050D5B5CD38  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  9: 00000050D5B71350  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  10: 00000050D5BE5D20  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  11: 00000050D5BE8D38  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  12: 00000050D5BEED38   58 SentHeaders 200 POST https://service.contoso.com/Service/JSONService
  13: 00000050D5BF0D38  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  14: 00000050D5BF2D50  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  15: 00000050D5BF4D38  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  16: 00000050D5BF6D58  --- Finished    --- POST https://service.contoso.com/Service/JSONService
  17: 00000050D5BF8D38  --- Finished    --- POST https://service.contoso.com/Service/JSONService