【问题标题】:How to Log a RESTful Service using Spring AOP in ASP.Net如何在 ASP.Net 中使用 Spring AOP 记录 RESTful 服务
【发布时间】:2012-06-05 09:52:44
【问题描述】:

我有一个 Restful 服务,它在传递产品代码时返回产品信息。 界面看起来像

 [OperationContract]
    [WebInvoke(UriTemplate = "Product/{ProductCode}", Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Product GetProductInformation(String ProductCode);

我通过输入 URI 从浏览器访问服务。

我正在通过 Spring AOP 实现日志。如何使用 Spring AOP 拦截方法。我尝试过使用 NameMatchMethodPointcutAdvisor,但在访问服务之前我没有使用 spring 创建服务对象,它无法拦截。有没有可能的方法来实现这个日志记录?

【问题讨论】:

    标签: asp.net spring rest logging aop


    【解决方案1】:

    终于找到答案了..

    对某人有帮助..

    通过允许spring工厂创建服务对象,可以实现拦截。为此,在服务主机 svc 文件中添加工厂属性,如下所示。

    <%@ ServiceHost Language="C#" Debug="true" Service="Servicename" Factory="Spring.ServiceModel.Activation.ServiceHostFactory" %>
    

    为了防止.net在&lt;system.webServer&gt;handlerspart下的web.config文件中创建服务对象,删除以下

    <modules runAllManagedModulesForAllRequests="true"/>
    

    并添加

    <remove name="WebServiceHandlerFactory-Integrated"/>
    

    【讨论】:

      猜你喜欢
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2019-11-24
      • 2021-12-26
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      相关资源
      最近更新 更多