Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

wcf - MvcMiniProfiler profiling web app and lower layers

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...