I want to set the time between two special moments:
- the start moment The method will be called IDispatchMessageInspector .ReceiveRequest - After the end of the moment the method will be called IDispatchMessageInspector. In fact, I want to calculate the time that the service call is necessary to execute the user code. I thought that IDispatchMessageInspector is a good place to hook those two ways but unfortunately I do not know how to associate AfterReceiveRequest for the message related to the next response. Thank you.
There is a parameter inspector that I once wrote to measure the performance of my WCF service methods . Notice that one has been started and returned to the call before
method that you get permission to get it in the AfterCall
method in the parameter returns:
public class PerformanceCountersInspector: IParameterInspector Opreshnnam Phlecol (string {public object, object [] input) {return Stopvockstart New (); } After public zero (string operation name, object [] output, object return value, object correlation state) {var watch = (stopwatch) correlation state; Watch.Stop (); Var time = clock Elapsed milliseconds; // do something with the result}}
The difference here is that the time taken for using the parameter inspector will not take the time taken to serialize the input / output parameter. It will only account for operation time. If you want to include serialization times, you can use the correlationState
also works in the method.
Update:
You Web. Configure the parameter inspector in the config. Behavior extension:
public class PerformanceCountersBehaviorExtension: Wyvharvistaraktethnilement, IServiceBehavior {public override behave received {{return typeof (PerformanceCountersBehaviorExtension); }} Safe Override Object CreateBehavior () {This Return; } Void IServiceBehavior.AddBindingParameters (ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection & amp; Lift; ServiceEndpoint & gt; endpoint, binding parameter collection Binding Parameters) {} void IServiceBehavior.ApplyDispatchBehavior (statements describing the service, ServiceHostBase Sewahostbej) {foreach ( ChannelDispatcher channelDispatcher serviceHostBase.ChannelDispatchers) {foreach (var endpoint in channel dispatcher. Andepoints) {foreach (diversified operation in the end. Dispatch time. operation) {var inspector = new protesters inspector (); Operation.ParameterInspectors.Add (Inspector); }}}} Void IServiceBehavior.Validate (ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) {}}
And in your configuration file, you register the extension:
& Lt; Services & gt; & Lt; Service name = "MyAssembly.MyService" behavior configuration = "ReturnFaults" & gt; & Lt; Endpoint address = "" binding = "basic HttpBinding" contract = "MyAssembly.IMyServiceContract" / & gt; & Lt; Endpoint address = "Max" binding = "MaxHttpending" contract = "IMAXADEXXchange" /> & Lt; / Services & gt; & Lt; / Services & gt; & Lt; Behavior & gt; & Lt; ServiceBehaviors & gt; & Lt; Behavior Name = "ReturnFast" & gt; & Lt; Service debug includes ExceptionDetailInFaults = "true" /> & Lt; ServiceMetadata httpGetEnabled = "true" /> & Lt; Perf counter / & gt; & Lt; / Behavior & gt; & Lt; / ServiceBehaviors & gt; & Lt; / Behavior & gt; & Lt; Extensions & gt; & Lt; BehaviorExtensions & gt; & Lt; Add name = "Perf quarter" type = "MyAssembly. Prformensupyogkrtautpadk extension, Mayasppand, Version = 1.0.0.0, Culture = neutral, Sarwajnikkitokn = null" / & gt; & Lt; / BehaviorExtensions & gt; & Lt; / Extensions & gt;
No comments:
Post a Comment