开发者

Pass information from SoapExtension to WebMethod

开发者 https://www.devze.com 2023-02-28 16:48 出处:网络
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

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.


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号