2009-06-19 4 views
7

모든 SOAP 요청 및 응답을 기록하기위한 SoapExtension이 있습니다. MS Soap Toolkit (OnBase Workflow)을 사용하는 응용 프로그램의 호출에 대해서는 정상적으로 작동합니다. 그러나 html 페이지에서 $ .ajax()가 작성한 호출에는 작동하지 않습니다.ScriptService WebService 요청을 추적하는 방법은 무엇입니까?

[WebService(Namespace = XmlSerializationService.DefaultNamespace)] 
[ScriptService] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
public class DepartmentAssigneeService : WebService 
{ 
    private readonly DepartmentAssigneeController _controller = new DepartmentAssigneeController(); 

    /// <summary> 
    /// Fetches the role items. 
    /// </summary> 
    /// <returns></returns> 
    [WebMethod] 
    [SoapLog] 
    public ListItem[] FetchDepartmentItems() 
    { 
     return CreateListItems(_controller.FetchDepartments()); 
    } 
} 

을 그리고 여기에 SoapExtension 및 SoapExtensionAttribute의 기본은 다음과 같습니다 :

$.ajax({ 
    type: "POST", 
    url: url, 
    data: data, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json" 
}); 

그것은 WebService에와 ScriptService에 표시된 ASP.NET 3.5 WebService를 호출의 속성 :

public class LoggingSoapExtension : SoapExtension, IDisposable { /*...*/ } 

[AttributeUsage(AttributeTargets.Method)] 
public sealed class SoapLogAttribute : SoapExtensionAttribute { /*...*/ } 
여기 예입니다

$ .ajax() 요청에서 LoggingSoapExtension을 실행할 수있는 항목이 누락 되었습니까?

업데이트

@ 크리스 Brandsma

당신이 JSON을 요청하는 것은 웹 서비스 (dataType와 "JSON")를 통해 대신 XML의 결과 때문이있을 수 있습니다. 따라서 ScriptService 속성이 활성화되어 있지만 SOAP 메시지를 보내지 않습니다.

왜 SoapExtension이 작동하지 않는지에 대한 답변입니다. ScriptService로 추적을위한 제안? 마음에 오는 유일한 것은 요청을 기록하는 메소드를 제공하는 ScriptService 기본 클래스입니다. 그런 다음 모든 ScriptService WebService의 모든 WebMethod에서이 메서드를 호출해야합니다 (필자는 상당수 있습니다). 가능한 경우 SoapExtension 특성처럼 깨끗하고 단순한 것을 사용하고 싶습니다.

답변

2

해결책을 찾았습니다. IHttpModule을 사용하여 어떤 것 (SOAP, JSON, 폼 등)의 요청도 로깅 할 수 있습니다. 아래 구현에서 모든 .asmx 및 .ashx 요청을 기록하도록 선택했습니다. 이것은 질문에서 LoggingSoapExtension을 대체합니다.

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); 
      } 
     } 
    } 
} 

Capturing HTML generated from ASP.NET에서 많이 빌 렸습니다.

+0

CapturedStream이란 무엇입니까? – Naor

+0

http://stackoverflow.com/questions/386487/capturing-html-generated-from-asp-net/386648#386648의 ResponseCaptureStream과 동일합니다. – jrummell

1

웹 서비스 (dataType : "json")를 통해 XML 대신 Json 결과를 요청하기 때문일 수 있습니다. 따라서 ScriptService 속성이 활성화되어 있지만 SOAP 메시지를 보내지 않습니다.

dataType을 xml로 변경하고 해당 데이터가 작동하는지 확인할 수 있습니다.

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

또한, 로깅을위한 또 다른 옵션은 Log4Net이 될 것입니다. 그것은 당신을 위해 훨씬 더 다목적 수 있습니다.

+0

저는 XML을 구문 분석하고 싶지 않기 때문에 json을 요청하고 있습니다. ScriptService가 SOAP를 사용하지 않는다면 의미가 있습니다. 감사! – jrummell

0

Fiddler (IE는 주로 Firefox 용) 또는 Firebug (Firefox 용)는 클라이언트 쪽 요청 및 응답을 보는 데 매우 중요한 도구입니다.

+0

테스트에 도움이되지만 요청에 대한 완전한 로그가 필요합니다. – jrummell