473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to log SOAP messages on the client side

I know I can use SOAPExtension to read request and response SOAP messages on
the server side for a Web Method. Is there a way to do the same thing on the
client side when you make a Web Service call? I would like to see what is
going out and what is coming in. Thanks for your help.

Nov 23 '05 #1
1 10160
This is the same:

this example was taken from Remoting WebService (Amit Kalani):

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace BugTrackerClient
{
/// <summary>
/// Summary description for SoapDisplayExtension.
/// </summary>
public class SoapDisplayExtension : SoapExtension
{
public SoapDisplayExtension()
{
//
// TODO: Add constructor logic here
//
}

// Variables to hold the original stream
// and the stream that we return
private Stream originalStream;
private Stream internalStream;

// Version called if configured with a config file
public override object GetInitializer(
System.Type serviceType)
{
// Not used in this example, but it//s
// declared abstract in the base class
return null;
}

// Called the first time the Web service is used
// Version called if configured with an attribute
public override object GetInitializer(
LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
// Not used in this example, but it//s
// declared abstract in the base class
return null;
}

// Called each time the Web service is used
// And gets passed the data from
// GetInitializer() method
public override void Initialize(
object initializer)
{
// Not used in this example, but it//s
// declared abstract in the base class
}

// The ChainStream() method gives us a chance
// to grab the SOAP messages as they go by
public override System.IO.Stream ChainStream(
System.IO.Stream stream)
{
// Save the original stream
originalStream = stream;
// Create and return our own in its place
internalStream = new MemoryStream();
return internalStream;
}

// The ProcessMessage() method is where we do our work
public override void ProcessMessage(
System.Web.Services.Protocols.SoapMessage message)
{
// Determine the stage and take appropriate action
switch(message.Stage)
{
case SoapMessageStage.BeforeSerialize:
// About to prepare a SOAP Response
break;

case SoapMessageStage.AfterSerialize:
// SOAP response is all prepared
internalStream.Position = 0;
// Get a Transform ready
XslTransform xslt = new XslTransform();
xslt.Load(@"..\..\Identity.xslt");
// Load the raw XML into an XML document
XmlDocument xd = new XmlDocument();
xd.Load(internalStream);
// Use the transform to pretty print it
MemoryStream ms = new MemoryStream();
xslt.Transform(xd, null, ms);
// And drop the results
// to a TextBox control
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
DisplayMessage f = new DisplayMessage();
f.txtMessage.Text = sr.ReadToEnd();
f.Show();
// Copy the passed message
// to the other stream
internalStream.Position = 0;
CopyStream(
internalStream, originalStream);
internalStream.Position = 0;
break;

case SoapMessageStage.BeforeDeserialize:
// About to handle a SOAP request
// Copy the passed message
// to the other stream
CopyStream(
originalStream, internalStream);
internalStream.Position = 0;
// Get a Transform ready
XslTransform xslt1 = new XslTransform();
xslt1.Load(@"..\..\Identity.xslt");
// Load the raw XML into an XML document
XmlDocument xd1 = new XmlDocument();
xd1.Load(internalStream);
// Use the transform to pretty print it
MemoryStream ms1 = new MemoryStream();
xslt1.Transform(xd1, null, ms1);
// And drop the results
// to a TextBox control
ms1.Position = 0;
StreamReader sr1 = new StreamReader(ms1);
DisplayMessage f1 = new DisplayMessage();
f1.txtMessage.Text = sr1.ReadToEnd();
f1.Show();
internalStream.Position = 0;
break;

case SoapMessageStage.AfterDeserialize:
// SOAP request has been deserialized
break;
}
}

// Helper function to copy one stream to another
private void CopyStream(Stream fromStream,
Stream toStream)
{
try
{
StreamReader sr =
new StreamReader(fromStream);
StreamWriter sw =
new StreamWriter(toStream);
sw.WriteLine(sr.ReadToEnd());
sw.Flush();
}
catch (Exception ex)
{
// Log the exception
}
}
}
}

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Hans Kesting | last post by:
Hi, I'm trying to create a client for some webservice. BUT I have only limited information: * no WSDL available ("expected Q1-06") (it seems to be written in Java) * I don't have access (yet)...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
16
by: MR | last post by:
my soap messages to a remote site are failing. as far as i can tell the only differences between what my SOAP message looks liek and what they want are in the SOAP envelope SInce they don't have a...
1
by: Paul | last post by:
Hi, I have a web service application that uses AXIS at the server side and C# at the client side. the C# client code was generated using wsdl.exe. When AXIS raised an exception, it sends the...
3
by: Tony Clark | last post by:
Hi, I am creating a network application and want to use SOAP messages to communicate between clients (I am not consuming a web service!!), does anyone know of any good tutorials (or sample code)...
0
by: maraujo | last post by:
Hi, I have built a customized soap extension in order to log soap messages in client side. Is it possible? On every webservice call, I want to log all soap messages in client side (c:\log.txt...
6
by: Hao | last post by:
There is a wield issue in inspecting the network traffic on the web service client side. There are two soap calls if credentials are used. The first call has no credentials and is rejected by the...
3
by: ZAAN | last post by:
Hi, I'm developing an application in PHP5, which interacts with another system written in Delphi (of another company). I've prepared the Web Service - WSDL, Client and Server (only stub) side....
5
by: =?Utf-8?B?SmltbWVy?= | last post by:
Hello, I've been trying to create a WCF SOAP Router Service that can forward not just the message body but also any security headers set by the originator of the message. The destination service...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.