using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher; using System.Net; /// /// taken from http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/fa3f4c55-5835-43f2-892f-737b4bccb598 /// public class MyInspector : IClientMessageInspector, IEndpointBehavior { // These lists store the messages for later retrieval. public List sentMessages = new List(); public List receivedMessages = new List(); #region IClientMessageInspector Members public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { // Save the reply to the list. receivedMessages.Add(reply.ToString()); } public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) { // Save the request to the list. sentMessages.Add(request.ToString()); return null; } #endregion #region IEndpointBehavior Members public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { // Add this implementation to the inspectors. clientRuntime.MessageInspectors.Add(this); } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { } public void Validate(ServiceEndpoint endpoint) { } #endregion }