Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MiniProfiler.WCF.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>MiniProfiler.WCF</id>
<version>3.0.12.1-wcffix-006</version>
<version>3.0.12.1-wcffix-009</version>
<authors>Marc Gravell, Sam Saffron, Jarrod Dixon</authors>
<owners>Marc Gravell, Sam Saffron, Jarrod Dixon</owners>
<description>MiniProfiler integration for WCF</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<HintPath>..\packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -122,6 +123,7 @@
<Compile Include="Storage\MultiStorageProviderTests.cs" />
<Compile Include="Storage\TestHttpRuntimeCacheStorage.cs" />
<Compile Include="UnitTestStopwatch.cs" />
<Compile Include="WCF\WcfMiniProfilerDispatchInspectorTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand All @@ -138,11 +140,16 @@
<Project>{7F18DC76-61A2-4E7D-BA5A-FE159E789362}</Project>
<Name>StackExchange.Profiling.EntityFramework</Name>
</ProjectReference>
<ProjectReference Include="..\StackExchange.Profiling.Wcf\StackExchange.Profiling.Wcf.csproj">
<Project>{c471b0e5-0ae4-48e0-a938-02aeda030c5e}</Project>
<Name>StackExchange.Profiling.Wcf</Name>
</ProjectReference>
<ProjectReference Include="..\StackExchange.Profiling\StackExchange.Profiling.csproj">
<Project>{386222BD-6B6E-480F-A342-8DE1AB516E2C}</Project>
<Name>StackExchange.Profiling</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using NUnit.Framework;
using StackExchange.Profiling.Wcf;

namespace StackExchange.Profiling.Tests.WCF
{
[TestFixture]
public class WcfMiniProfilerDispatchInspectorTest
{
[Test]
public void WillSuppressSQlCommandTextInHeader()
{
MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider();
var profiler = MiniProfiler.Start(nameof(this.WillSuppressSQlCommandTextInHeader));
profiler.Root.AddCustomTiming("sql",
new CustomTiming(profiler, nameof(this.WillSuppressSQlCommandTextInHeader), 5));

var message = Message.CreateMessage(MessageVersion.Soap12, nameof(this.WillSuppressSQlCommandTextInHeader));

var wcfMiniProfilerDispatchInspector = new WcfMiniProfilerDispatchInspector(false);
wcfMiniProfilerDispatchInspector.BeforeSendReply(ref message, new MiniProfilerRequestHeader());

var resultHeader = message.Headers.GetHeader<MiniProfilerResultsHeader>(MiniProfilerResultsHeader.HeaderName,
MiniProfilerResultsHeader.HeaderNamespace);
Assert.AreEqual(0, resultHeader.ProfilerResults.Root.CustomTimings.Count());
}

[Test]
public void WillSerializeProfilerWithoutSqlCommandText()
{
MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider();
var profiler = MiniProfiler.Start(nameof(this.WillSuppressSQlCommandTextInHeader));

var message = Message.CreateMessage(MessageVersion.Soap12, nameof(this.WillSuppressSQlCommandTextInHeader));

var wcfMiniProfilerDispatchInspector = new WcfMiniProfilerDispatchInspector(false);
wcfMiniProfilerDispatchInspector.BeforeSendReply(ref message, new MiniProfilerRequestHeader());

var resultHeader = message.Headers.GetHeader<MiniProfilerResultsHeader>(MiniProfilerResultsHeader.HeaderName,
MiniProfilerResultsHeader.HeaderNamespace);
Assert.IsNull(resultHeader.ProfilerResults.Root.CustomTimings);
}
}
}
2 changes: 1 addition & 1 deletion StackExchange.Profiling.Wcf/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
[assembly: ComVisible(false)]
[assembly: Guid("a95b0bf2-e9cf-4029-b77a-85b9e66fd3d5")]
[assembly: AssemblyVersion("3.0.12.1")]
[assembly: AssemblyInformationalVersion("3.0.12.1-wcffix-006")]
[assembly: AssemblyInformationalVersion("3.0.12.1-wcffix-009")]
20 changes: 18 additions & 2 deletions StackExchange.Profiling.Wcf/WcfMiniProfilerBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace StackExchange.Profiling.Wcf
{
using System;
using System.Configuration;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;

Expand All @@ -9,6 +10,21 @@
/// </summary>
public class WcfMiniProfilerBehavior : BehaviorExtensionElement, IEndpointBehavior
{
[ConfigurationProperty("logSql")]
public bool LogSqlCommandText
{
get
{
if (bool.TryParse(this["logSql"]?.ToString(), out var val))
{
return val;
}
return false;
}

set => this["logSql"] = value;
}

/// <summary>
/// Gets the behaviour type.
/// </summary>
Expand Down Expand Up @@ -44,7 +60,7 @@ public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Di
/// <param name="endpointDispatcher">The endpoint dispatcher.</param>
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{
var inspector = new WcfMiniProfilerDispatchInspector();
var inspector = new WcfMiniProfilerDispatchInspector(this.LogSqlCommandText);
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
}

Expand All @@ -65,4 +81,4 @@ protected override object CreateBehavior()
return this;
}
}
}
}
14 changes: 14 additions & 0 deletions StackExchange.Profiling.Wcf/WcfMiniProfilerDispatchInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
/// </summary>
public class WcfMiniProfilerDispatchInspector : IDispatchMessageInspector
{
protected readonly bool _logSqlCommandText;

/// <summary>
/// true if the binding is using http.
/// </summary>
private bool _http;

public WcfMiniProfilerDispatchInspector(bool logSqlCommandText)
{
this._logSqlCommandText = logSqlCommandText;
}

/// <summary>
/// after the request is received.
/// </summary>
Expand Down Expand Up @@ -86,6 +93,13 @@ public void BeforeSendReply(ref Message reply, object correlationState)
miniProfiler.Root.RemoveTrivialTimings();
}

if ((false == this._logSqlCommandText) && (null != miniProfiler.Root.CustomTimings)
&& (miniProfiler.Root.CustomTimings.ContainsKey("sql")))
{
miniProfiler = miniProfiler.Clone();
miniProfiler.Root.CustomTimings.Remove("sql");
}

var header = new MiniProfilerResultsHeader
{
ProfilerResults = miniProfiler
Expand Down
2 changes: 1 addition & 1 deletion StackExchange.Profiling/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
[assembly: ComVisible(false)]
[assembly: Guid("f41f8a8f-55ef-44ac-beaf-d6fa475939a7")]
[assembly: AssemblyVersion("3.2.1.1")]
[assembly: AssemblyInformationalVersion("3.2.1.1-wcffix-004")]
[assembly: AssemblyInformationalVersion("3.2.1.1-wcffix-004-john")]
[assembly: InternalsVisibleTo("StackExchange.Profiling.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001172d8b313c5125b3503ab4656bc2c04305498b2c75560f2e4fdc70e22fd098b9fdce619c318b5fb92670406d2122c9912ee718cb24544f69b7a92a825bd6e439bf1b51cf8e32be536954881c067a81e3da26ca348f7a17de7dfc07ae6df14ce132a7cfcb6d5f53f939bc9f623ec0e5ff9edab439c04a9b8bf8c110ebe8908be")]