MvcMiniProfiler分析Web应用程序和较低层

dos*_*oss 14 wcf mvc-mini-profiler

我在我的ASP.NET MVC应用程序中设置并使用MiniProfiler.我的控制器通过WCF调用BLL,然后BLL与数据库进行通信.我希望看到WCF服务的分析以及我从Web应用程序中看到的现有分析.是否在所有服务调用中使MiniProfiler成为参数?

Pau*_*mke 21

在最近发布的MvcMiniProfiler中,他们添加了WCF支持(版本1.8或更高版本).这是一个让步于此工作的3个步骤:

添加参考

首先通过nuget在UI层和WCF层添加对MvcMiniprofiler和MvcMiniProfiler.WCF的引用(或者下载源代码并编译自己的代码).

设置WCF主机

其次,在服务主机的web.config中,您必须将miniprofiler添加为端点行为.所有配置部分都属于"configuration/system.serviceModel".

<endpointBehaviors>
   <behavior name="miniProfilerBehavior">
      <wcfMiniProfilerBehavior />
   </behavior>
</endpointBehaviors>
Run Code Online (Sandbox Code Playgroud)

然后添加行为扩展(请注意版本号需要与您的MvcMiniProfiler.WCF版本匹配):

<extensions>
    <behaviorExtensions>
      <add name="wcfMiniProfilerBehavior" type="MvcMiniProfiler.Wcf.WcfMiniProfilerBehavior, MvcMiniProfiler.Wcf, Version=1.8.0.0, Culture=neutral" />
    </behaviorExtensions>
 </extensions>
Run Code Online (Sandbox Code Playgroud)

然后设置端点以使用您设置的分析器行为:

<services>
  <service behaviorConfiguration="BaseBehavior" name="BSI.Something">
    <endpoint address="" behaviorConfiguration="miniProfilerBehavior" binding="basicHttpBinding" bindingConfiguration="http" contract="BSI.ISomething"/>
  </service>
 </services>
Run Code Online (Sandbox Code Playgroud)

取决于您的设置,但我不得不再添加一个web.config设置来运行所有请求的所有托管模块.此配置位于根"配置"部分中:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

设置WCF客户端

最后,设置wcf客户端通过执行上述相同操作来"打开"mvc探查器.

添加扩展名:

<extensions>
   <behaviorExtensions>
      <add name="wcfMiniProfilerBehavior" type="MvcMiniProfiler.Wcf.WcfMiniProfilerBehavior, MvcMiniProfiler.Wcf, Version=1.8.0.0, Culture=neutral" />
   </behaviorExtensions>
</extensions>
Run Code Online (Sandbox Code Playgroud)

添加行为:

<behaviors>
  <endpointBehaviors>
     <behavior name="wcfMiniProfilerBehavior">
        <wcfMiniProfilerBehavior />
     </behavior>
  </endpointBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

设置端点以使用该行为:

<client>
   <endpoint address="http://something/Something.svc" behaviorConfiguration="wcfMiniProfilerBehavior"
      binding="BasicHttpBinding" bindingConfiguration="BasicHttpBinding_HTTP"
      contract="BSL.ISomething" name="BasicHttpBinding_ISomething" />
</client>
Run Code Online (Sandbox Code Playgroud)

而且你已经完成了!

附注: MvcMiniProfiler如何实际工作在WCF上?基本上,客户端行为设置一个SOAP标头,告诉wcf主机打开分析器.它传递该标头,WCF主机端的端点行为将读取该标头.然后它会在主机中打开探查器.最后,当WCF主机回复客户端时,它将所有分析器的优点填充到SOAP响应头中,而SOAP响应头又由WCF客户端读取.非常巧妙.

  • 正如任何人看到的那样,在Nuget上没有MvcMiniProfiler.WCF或MiniProfiler.WCF打包你必须得到源代码并自己编译项目 (11认同)
  • 此外,他们更改了名称空间.对于2.0.4,我使用`<add name ="WcfMiniProfilerBehavior"type ="StackExchange.Profiling.Wcf.WcfMiniProfilerBehavior,MiniProfiler.Wcf"/>` (4认同)
  • 更新 - 现在可以在Nuget上使用MiniProfiler.WCF. (2认同)

Alp*_*pha 0

这是一种方法,但为了获取对库的引用,您必须在 MvcMiniProfiler 的较低层中添加引用。

在这种完全相同的情况下,我所做的是利用 MiniProfiler 作为单例提供的全局访问点。因此,我只是在较低层中添加了引用(删除了与 MVC 相关的内容,例如视图),并且只使用了 MiniProfiler.Current,就好像我在上层一样。

它就像一个魅力。:)