How to trace ScriptService WebService requests?

前端 未结 3 1845
你的背包
你的背包 2020-12-03 12:48

I have a SoapExtension that is intended to log all SOAP requests and responses. It works just fine for calls from an application using the MS Soap Toolkit (OnBase Workflow)

相关标签:
3条回答
  • 2020-12-03 12:52

    I found a solution. By using an IHttpModule I can log requests from anything (SOAP, JSON, forms, etc). In the implementation below, I've chosen to log all .asmx and .ashx requests. This replaces LoggingSoapExtension from the question.

    public class ServiceLogModule : IHttpModule
    {
        private HttpApplication _application;
        private bool _isWebService;
        private int _requestId;
        private string _actionUrl;
    
        #region IHttpModule Members
    
        public void Dispose()
        {
        }
    
        public void Init(HttpApplication context)
        {
            _application = context;
            _application.BeginRequest += ContextBeginRequest;
            _application.PreRequestHandlerExecute += ContextPreRequestHandlerExecute;
            _application.PreSendRequestContent += ContextPreSendRequestContent;
        }
    
        #endregion
    
        private void ContextPreRequestHandlerExecute(object sender, EventArgs e)
        {
            _application.Response.Filter = new CapturedStream(_application.Response.Filter,
                                                              _application.Response.ContentEncoding);
        }
    
        private void ContextBeginRequest(object sender, EventArgs e)
        {
            string ext = VirtualPathUtility.GetExtension(_application.Request.FilePath).ToLower();
            _isWebService = ext == ".asmx" || ext == ".ashx";
    
            if (_isWebService)
            {
                ITraceLog traceLog = TraceLogFactory.Create();
                _actionUrl = _application.Request.Url.PathAndQuery;
    
                StreamReader reader = new StreamReader(_application.Request.InputStream);
                string message = reader.ReadToEnd();
                _application.Request.InputStream.Position = 0;
    
                _requestId = traceLog.LogRequest(_actionUrl, message);
            }
        }
    
        private void ContextPreSendRequestContent(object sender, EventArgs e)
        {
            if (_isWebService)
            {
                CapturedStream stream = _application.Response.Filter as CapturedStream;
                if (stream != null)
                {
                    ITraceLog traceLog = TraceLogFactory.Create();
                    traceLog.LogResponse(_actionUrl, stream.StreamContent, _requestId);
                }
            }
        }
    }
    

    I borrowed heavily from Capturing HTML generated from ASP.NET.

    0 讨论(0)
  • 2020-12-03 12:56

    It might be because you are requesting Json results instead of XML via your web service (dataType: "json"). So the ScriptService attribute is being activated, but you are not sending SOAP messages.

    You could change the dataType to xml and see if that works.

    http://docs.jquery.com/Ajax/jQuery.ajax#options

    Also, another option for logging would be Log4Net. It could be a lot more versatile for you.

    0 讨论(0)
  • 2020-12-03 13:02

    Fiddler (for IE primarily, but now for firefox) or Firebug (for firefox) are invaluable tools for watching your client-side requests and responses.

    0 讨论(0)
提交回复
热议问题