IDispatchMessageInspector.BeforeSendReply Method
Called after the operation has returned but before the reply message is sent.
Namespace: System.ServiceModel.Dispatcher
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Parameters
- reply
- Type: System.ServiceModel.Channels.Message
The reply message. This value is null if the operation is one way.
- correlationState
- Type: System.Object
The correlation object returned from the AfterReceiveRequest method.
Use the BeforeSendReply method to perform custom behavior prior to sending the return message. The correlationState is the object returned from the AfterReceiveRequest method that you can use to perform correlation between inbound and outbound calls to support your behavior.
The following code example shows a basic IDispatchMessageInspector that writes a string to the console when it is invoked.
#region IDispatchMessageInspector Members public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext) { Console.WriteLine("IDispatchMessageInspector.AfterReceiveRequest called."); return null; } public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { Console.WriteLine("IDispatchMessageInspector.BeforeSendReply called."); } #endregion
The following code example shows the implementation of an IServiceBehavior that adds the Inspector IDispatchMessageInspector to the DispatchRuntime.MessageInspectors collection.
#region IServiceBehavior Members public void AddBindingParameters( ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters ) { return; } public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { foreach (ChannelDispatcher chDisp in serviceHostBase.ChannelDispatchers) { foreach (EndpointDispatcher epDisp in chDisp.Endpoints) { epDisp.DispatchRuntime.MessageInspectors.Add(new Inspector()); foreach (DispatchOperation op in epDisp.DispatchRuntime.Operations) op.ParameterInspectors.Add(new Inspector()); } } }
The following code example shows the use of an application configuration file to load the service behavior that inserts the Inspector IDispatchMessageInspector.
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="metadataSupport">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/SampleService" />
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceInterceptors />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add
name="serviceInterceptors"
type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
<configuration>
<system.serviceModel>
<services>
<service
name="Microsoft.WCF.Documentation.SampleService"
behaviorConfiguration="inspectorBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/SampleService" />
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
contract="Microsoft.WCF.Documentation.ISampleService"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="inspectorBehavior">
<serviceInspectors />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add
name="serviceInspectors"
type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.