我已经在我的ASP.NET MVC应用程序中设置并运行了MiniProfiler。我的控制器通过WCF调用BLL,而BLL又与数据库通信。我希望除了从web应用程序看到的现有分析之外,还希望看到来自WCF服务的分析。是否需要在所有服务调用中将MiniProfiler设置为参数?
发布于 2011-09-26 21:33:01
在最近发布的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设置,以便为所有请求运行所有托管模块。此配置位于根目录的"configuration“部分:
<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-26 10:49:46
这是一种方法,但是为了获得对库的引用,无论如何都必须在MvcMiniProfiler的较低层中添加引用。
在这种情况下,我所做的就是利用MiniProfiler作为单例提供的全局访问点。因此,我只是在较低层添加了引用(删除了与MVC相关的内容,如视图),并使用了MiniProfiler.Current,就好像我在较高层一样。
它就像一种护身符。:)
https://stackoverflow.com/questions/7530027
复制相似问题