my objective is to capture response & request xml when i am calling web service from my win form apps.i am getting object reference not set error when i am trying to capture xml.
here is my class library source code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Net;
using System.Xml;
namespace SoapLogger
{
public class TraceExtension : SoapExtension
{
private Stream oldStream;
private Stream newStream;
private static XmlDocument xmlRequest;
///
/// Gets the outgoing XML request sent to PayPal
///
public static XmlDocument XmlRequest
{
get { return xmlRequest; }
}
private static XmlDocument xmlResponse;
///
/// Gets the incoming XML response sent from PayPal
///
public static XmlDocument XmlResponse
{
get { return xmlResponse; }
}
///
/// Save the Stream representing the SOAP request
/// or SOAP response into a local memory buffer.
///
///
///
public override Stream ChainStream(Stream stream)
{
oldStream = stream;
newStream = new MemoryStream();
return newStream;
}
///
/// If the SoapMessageStage is such that the SoapRequest or
/// SoapResponse is still in the SOAP format to be sent or received,
/// save it to the xmlRequest or xmlResponse property.
///
///
public override void ProcessMessage(SoapMessage message)
{
switch (message.Stage)
{
case SoapMessageStage.BeforeSerialize:
break;
case SoapMessageStage.AfterSerialize:
xmlRequest = GetSoapEnvelope(newStream);
CopyStream(newStream, oldStream);
break;
case SoapMessageStage.BeforeDeserialize:
CopyStream(oldStream, newStream);
xmlResponse = GetSoapEnvelope(newStream);
break;
case SoapMessageStage.AfterDeserialize:
break;
}
}
///
/// Returns the XML representation of the Soap Envelope in the supplied stream.
/// Resets the position of stream to zero.
///
///
///
private XmlDocument GetSoapEnvelope(Stream stream)
{
XmlDocument xml = new XmlDocument();
stream.Position = 0;
StreamReader reader = new StreamReader(stream);
xml.LoadXml(reader.ReadToEnd());
stream.Position = 0;
return xml;
}
///
/// Copies a stream.
///
///
///
private void CopyStream(Stream from, Stream to)
{
TextReader reader = new StreamReader(from);
TextWriter writer = new StreamWriter(to);
writer.WriteLine(reader.ReadToEnd());
writer.Flush();
}
#region NoOp
///
/// Included only because it must be implemented.
///
///
///
///
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return null;
}
///
/// Included only because it must be implemented.
///
///
///
public override object GetInitializer(Type WebServiceType)
{
return null;
}
///
/// Included only because it must be implemented.
///
///
public override void Initialize(object initializer)
{
}
#endregion NoOp
}
}
here i will show how i am calling web service from win apps
private void button1_Click(object sender, EventArgs e)
{
using (ServiceRef.TestServiceSoapClient oService = new ServiceRef.TestServiceSoapClient())
{
textBox1.Text = oService.HelloWorld("Sudip");
var soapRequest = SoapLogger.TraceExtension.XmlRequest.InnerXml;
var soapResponse = SoapLogger.TraceExtension.XmlResponse.InnerXml;
}
}
this two line is giving object reference error
var soapRequest = SoapLogger.TraceExtension.XmlRequest.InnerXml;
var soapResponse = SoapLogger.TraceExtension.XmlResponse.InnerXml;
i just could not figure out why i am getting error.
in win form apps has one app.config where i register my class library assembly to capture the xml. here is my app.config details
when i search google just to know how to capture request/response xml then i got this kind of many article. i followed many but nothing works.
this url i followed to get the job done http://jramirezdev.net/blog/c-tip-capturar-los-mensajes-soap-de-un-servicio-asmx-que-hemos-referenciado
what kind of mistake i am making not clear. i set the break point at every method in my class library method but when web service call no method got executed in the class library. i dont want to use any tool like wireshark,fiddler to capture the request/response xml rather want to do same thing programatically.
so please guide me what is my mistake. why i am getting object reference not set error. please have a look at my code or go to the url link and tell me what is wrong in my approach.
angel adinolffiPosted Jul 1, 2014, 6:32 PM
http://www.systemdeveloper.org/2014/06/tracesoapmessage/
I hope it will be useful, in my fuciono me pretty well
angel adinolffiPosted Jul 1, 2014, 6:32 PM
http://www.systemdeveloper.org/2014/06/tracesoapmessage/
I hope it will be useful, in my fuciono me pretty well
angel adinolffiPosted Jul 1, 2014, 6:32 PM
http://www.systemdeveloper.org/2014/06/tracesoapmessage/
I hope it will be useful, in my fuciono me pretty well
angel adinolffiPosted Jul 1, 2014, 6:32 PM
http://www.systemdeveloper.org/2014/06/tracesoapmessage/
I hope it will be useful, in my fuciono me pretty well
angel adinolffiPosted Jul 1, 2014, 6:32 PM
http://www.systemdeveloper.org/2014/06/tracesoapmessage/
I hope it will be useful, in my fuciono me pretty well
angel adinolffiPosted Jul 1, 2014, 6:32 PM
http://www.systemdeveloper.org/2014/06/tracesoapmessage/
I hope it will be useful, in my fuciono me pretty well
angel adinolffiPosted Nov 28, 2013, 3:45 PM
Obs: targetFramework="4.0"