14

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

4

2 回答 2

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>

然后添加行为扩展(注意版本号需要与您的 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 客户端又会读取该响应标头。相当巧妙。

于 2011-09-26T13:33:01.427 回答
0

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

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

它就像一个魅力。:)

于 2011-09-26T02:49:46.267 回答