1

I currently have a large set of ASMX web services that log the incoming and outgoing objects by serializing them to xml and storing that xml in my database; that logging process takes place in the web method itself.(I know. I know. I should be using WCF, and I am trying to push that ball up the hill, but my organization is old and slow)

Rather than serializing the object, I would prefer to just use a Soap Extension and log the whole SOAP message they send in and the whole SOAP message I return. Using Microsoft's example as a base, I have that working great. My problem is that when I log the SOAP request to the database, I generate a unique key that matches that request and can be used to find the request in the database. I would like to pass that key to my web method so that it can be used to log other information that corresponds to the request (errors, metrics, etc). However, I cannot figure out a way to get that key to the web method so that the web method can store additional information in the database about the request.

Is this possible, and if so, what is the best method?

Thank you for your time.

Zach Green
  • 3,421
  • 4
  • 29
  • 32

2 Answers2

1

You should look into logging using the CorrelationManager class. You would start the logical operation in the SoapExtension on the request, and stop it on the corresponding reply. Your logs should then show a clean match of request to reply, including the additional information you want to log.

The unique ID (a GUID) would be available as Trace.CorrelationManager.ActivityId.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • I like the idea of using this class; I have never used it before. One problem I will have to work around is that I am on Oracle, and a .NET GUID does not perform as well as an Oracle sequence when indexed. I could do some type of hack to use the GUID by tempoarily storing it in the column I use for the response XML until the last operation where I actually store the final XML that I return to the user. – Zach Green Apr 26 '11 at 18:17
  • Maybe I could create a static dictionary that relates a GUID to my Oracle sequence value. – Zach Green Apr 26 '11 at 18:24
  • @Zach: you could, but is this data going to be accessed so frequently that index performance is a concern? – John Saunders Apr 26 '11 at 19:31
  • It is enough of a reason once it is teamed with my desire to not fight for a month with the DBAs to get the column data type changed (again, my org is old and slow). I implemented a thread safe dictionary (with info from here: http://stackoverflow.com/questions/157933/whats-the-best-way-of-implementing-a-thread-safe-dictionary-in-net), and so far I am headed in a good direction. Thanks for your help. – Zach Green Apr 27 '11 at 12:10
0

Why not just have a global flag (or something more sophisticated to prevent multithreading issues), set that in the server-side soap extension to the current request ID and read it in the server side method?

Filip
  • 51
  • 1
  • 4
  • That thread safety is exactly what worried me about using some type of global flag. I could have many simultaneous calls, and I need to be certain that global is safe across all the calls. – Zach Green Apr 26 '11 at 18:24