asp.net - Log both webservice Request, Response in SoapExtension -
i using soapextension log both webservice request, response when error occurs in webservice. both request , response xmldocument's have incorrect data. can review code see doing wrong? if unable centralize changes in soapextension, go adding logging code around each webservice endpoint.
using system; using system.io; using system.web.services.protocols; using system.xml; using elmah; public class elmahsoapextensionv2 : soapextension { private stream oldstream; private stream newstream; public static xmldocument xmlrequest { get; private set; } public static xmldocument xmlresponse { get; private set; } public override stream chainstream(stream stream) { oldstream = stream; newstream = new memorystream(); return newstream; } public override void processmessage(soapmessage soapmessage) { switch (soapmessage.stage) { case soapmessagestage.beforeserialize: break; case soapmessagestage.afterserialize: xmlrequest = getsoapenvelope(newstream); if (soapmessage.exception != null) { var exception = soapmessage.exception.getbaseexception(); exception.data.add("soaprequest", xmlrequest.outerxml); exception.data.add("soapresponse", xmlresponse.outerxml); errorsignal.fromcurrentcontext().raise(exception); } copystream(newstream, oldstream); break; case soapmessagestage.beforedeserialize: copystream(oldstream, newstream); xmlresponse = getsoapenvelope(newstream); break; case soapmessagestage.afterdeserialize: break; } } private static xmldocument getsoapenvelope(stream stream) { var xmldocument = new xmldocument(); stream.position = 0; var streamreader = new streamreader(stream); xmldocument.loadxml(streamreader.readtoend()); stream.position = 0; return xmldocument; } private static void copystream(stream streamfrom, stream streamto) { var textreader = new streamreader(streamfrom); var textwriter = new streamwriter(streamto); textwriter.writeline(textreader.readtoend()); textwriter.flush(); } #region myregion public override object getinitializer(logicalmethodinfo methodinfo, soapextensionattribute attribute) { return null; } public override object getinitializer(type webservicetype) { return null; } public override void initialize(object initializer) { } #endregion }
solved removing "static" property xmlrequest, xmlresponse properties. "xmlresponse" during "soapmessagestage.afterserialize" process , "xmlrequest" during "soapmessagestage.beforeserialize" process. had switched.
using system; using system.io; using system.web.services.protocols; using system.xml; using elmah; public class elmahsoapextensionv2 : soapextension { private stream oldstream; private stream newstream; public xmldocument xmlrequest { get; private set; } public xmldocument xmlresponse { get; private set; } public override stream chainstream(stream stream) { oldstream = stream; newstream = new memorystream(); return newstream; } public override void processmessage(soapmessage soapmessage) { switch (soapmessage.stage) { case soapmessagestage.beforeserialize: break; case soapmessagestage.afterserialize: xmlresponse = getsoapenvelope(newstream); if (soapmessage.exception != null) { var exception = soapmessage.exception.getbaseexception(); exception.data.add("soaprequest", xmlrequest.outerxml); exception.data.add("soapresponse", xmlresponse.outerxml); errorsignal.fromcurrentcontext().raise(exception); } copystream(newstream, oldstream); break; case soapmessagestage.beforedeserialize: copystream(oldstream, newstream); xmlrequest = getsoapenvelope(newstream); break; case soapmessagestage.afterdeserialize: break; } } private static xmldocument getsoapenvelope(stream stream) { var xmldocument = new xmldocument(); stream.position = 0; var streamreader = new streamreader(stream); xmldocument.loadxml(streamreader.readtoend()); stream.position = 0; return xmldocument; } private static void copystream(stream streamfrom, stream streamto) { var textreader = new streamreader(streamfrom); var textwriter = new streamwriter(streamto); textwriter.writeline(textreader.readtoend()); textwriter.flush(); } #region myregion public override object getinitializer(logicalmethodinfo methodinfo, soapextensionattribute attribute) { return null; } public override object getinitializer(type webservicetype) { return null; } public override void initialize(object initializer) { } #endregion }
Comments
Post a Comment