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

发布于 2024-12-06 16:33:26 字数 150 浏览 3 评论 0原文

我已在 ASP.NET MVC 应用程序中设置并运行 MiniProfiler。我的控制器通过 WCF 调用 BLL,而 BLL 又与数据库通信。我希望看到 WCF 服务的分析以及我从 Web 应用程序看到的现有分析。是否是在所有服务调用中将 MiniProfiler 作为参数的情况?

I have MiniProfiler set up and working in my ASP.NET MVC app. My controllers make calls via WCF to a BLL which in turn talks to the database. I would like to see profiling from the WCF service alongside the existing profiling I see from the web app. Is it a case of making MiniProfiler a parameter in all service calls?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度 2024-12-13 16:33:26

在最近发布的 MvcMiniProfiler 中,他们添加了 WCF 支持(版本 1.8 或更高版本)。这是完成此工作的 3 个步骤过程:

添加引用

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

设置 WCF 主机

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

<endpointBehaviors>
   <behavior name="miniProfilerBehavior">
      <wcfMiniProfilerBehavior />
   </behavior>
</endpointBehaviors>

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

<extensions>
    <behaviorExtensions>
      <add name="wcfMiniProfilerBehavior" type="MvcMiniProfiler.Wcf.WcfMiniProfilerBehavior, MvcMiniProfiler.Wcf, Version=1.8.0.0, Culture=neutral" />
    </behaviorExtensions>
 </extensions>

然后设置端点以使用您设置的探查器行为:

<services>
  <service behaviorConfiguration="BaseBehavior" name="BSI.Something">
    <endpoint address="" behaviorConfiguration="miniProfilerBehavior" binding="basicHttpBinding" bindingConfiguration="http" contract="BSI.ISomething"/>
  </service>
 </services>

取决于您的设置,但我必须再添加一项 web.config 设置为所有请求运行所有托管模块。此配置位于根“配置”部分:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

设置 WCF 客户端

最后,通过执行与上面相同的操作来设置 WCF 客户端以“打开”mvc 探查器。

添加扩展:

<extensions>
   <behaviorExtensions>
      <add name="wcfMiniProfilerBehavior" type="MvcMiniProfiler.Wcf.WcfMiniProfilerBehavior, MvcMiniProfiler.Wcf, Version=1.8.0.0, Culture=neutral" />
   </behaviorExtensions>
</extensions>

添加行为:

<behaviors>
  <endpointBehaviors>
     <behavior name="wcfMiniProfilerBehavior">
        <wcfMiniProfilerBehavior />
     </behavior>
  </endpointBehaviors>
</behaviors>

设置端点以使用该行为:

<client>
   <endpoint address="http://something/Something.svc" behaviorConfiguration="wcfMiniProfilerBehavior"
      binding="BasicHttpBinding" bindingConfiguration="BasicHttpBinding_HTTP"
      contract="BSL.ISomething" name="BasicHttpBinding_ISomething" />
</client>

您就完成了!

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

In a recent release of the MvcMiniProfiler they added WCF support (version 1.8 or greater). This is a 3 step process to get this working:

Add References

First add references to the MvcMiniprofiler and MvcMiniProfiler.WCF in your UI layer and WCF layer via nuget (or download the source and compile your own).

Setup WCF Host

Second, within the web.config of the service host you have to add the miniprofiler as an endpoint behavior. All of the config sections belong in "configuration/system.serviceModel".

<endpointBehaviors>
   <behavior name="miniProfilerBehavior">
      <wcfMiniProfilerBehavior />
   </behavior>
</endpointBehaviors>

Then add the behavior extension (Note the version number needs to match your version of the MvcMiniProfiler.WCF):

<extensions>
    <behaviorExtensions>
      <add name="wcfMiniProfilerBehavior" type="MvcMiniProfiler.Wcf.WcfMiniProfilerBehavior, MvcMiniProfiler.Wcf, Version=1.8.0.0, Culture=neutral" />
    </behaviorExtensions>
 </extensions>

Then setup the endpoints to use the profiler behavior you setup:

<services>
  <service behaviorConfiguration="BaseBehavior" name="BSI.Something">
    <endpoint address="" behaviorConfiguration="miniProfilerBehavior" binding="basicHttpBinding" bindingConfiguration="http" contract="BSI.ISomething"/>
  </service>
 </services>

Depends on your setup but I had to add one more web.config setting to run all managed modules for all requests. This config is in the root "configuration" section:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Setup WCF Client

Last, setup the wcf client to "turn on" the mvc profiler by doing much the same above.

Add the extension:

<extensions>
   <behaviorExtensions>
      <add name="wcfMiniProfilerBehavior" type="MvcMiniProfiler.Wcf.WcfMiniProfilerBehavior, MvcMiniProfiler.Wcf, Version=1.8.0.0, Culture=neutral" />
   </behaviorExtensions>
</extensions>

Add a behavior:

<behaviors>
  <endpointBehaviors>
     <behavior name="wcfMiniProfilerBehavior">
        <wcfMiniProfilerBehavior />
     </behavior>
  </endpointBehaviors>
</behaviors>

Setup the endpoints to use that behavior:

<client>
   <endpoint address="http://something/Something.svc" behaviorConfiguration="wcfMiniProfilerBehavior"
      binding="BasicHttpBinding" bindingConfiguration="BasicHttpBinding_HTTP"
      contract="BSL.ISomething" name="BasicHttpBinding_ISomething" />
</client>

And you're done!

Side Note:
How does the MvcMiniProfiler actually work over WCF?
Basically the client behavior sets up a SOAP header that tells the wcf host to turn on the profiler. It passes that header along which is read by the endpoint behavior on the WCF host side. It then turns the profiler on in the host. Lastly when the WCF host is replying back to the client it stuffs all the profiler goodness into the SOAP response header which is in turn read by the WCF client. Pretty ingenious.

傲性难收 2024-12-13 16:33:26

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

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

它就像一个魅力。 :)

That's one method, but in order to get the reference to the libraries you would have to add references in the lower layers for MvcMiniProfiler anyway.

What I did in this very same situation is to take advantage of the global access point that MiniProfiler provides as a singleton. So, I just added the reference in the lower levels (deleted the stuff relative to MVC, such as the views) and just used MiniProfiler.Current as if I were on the upper layers.

It works like a charm. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文