I hope you know how to create a WCF proxy using SVCUTIL.EXE.
You can refer my old post ‘Create proxy of WCF web service with svcutil‘
Add the proxy class to your project and add reference to System.ServiceModel namespace.
use the below namespace’s in your project.
using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.ServiceModel.Dispatcher; using System.ServiceModel.Description;
Now add a class MessageViewerInspector as a nested class.
internal class MessageViewerInspector : IEndpointBehavior, IClientMessageInspector { #region Properties public string RequestMessage { get; set; } public string ResponseMessage { get; set; } #endregion #region IEndpointBehavior Members public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { // adds our inspector to the runtime clientRuntime.MessageInspectors.Add(this); } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { } public void Validate(ServiceEndpoint endpoint) { } #endregion #region IClientMessageInspector Members void IClientMessageInspector.AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { this.ResponseMessage = reply.ToString(); } object IClientMessageInspector.BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) { this.RequestMessage = request.ToString(); return null; } #endregion }
Now create your proxy object as below.
MessageViewerInspector inspector = new MessageViewerInspector(); ServiceSoapClient _Client=new ServiceSoapClient() _Client.Endpoint.EndpointBehaviors.Add(inspector);
the inspector object have 2 properties ‘RequestMessage’ and ‘ResponseMessage’ contain SOAP request and response after you called any operations through proxy.
You must be logged in to post a comment.