Hi Greg,
Create a SOAP extension (derive your class from SoapExtension).
In the ChainStream method save the original stream and in the ProcessMessage
method, write out the stream if
message.Stage==SoapMessageStage.BeforeDeserialize.
See the sample code below which is based on code found in "MCAS/MCSD
Developing XML Web Services and Server Components wth Visual C# .NET and the
..NET Framework Exam 70-320" by Amit Kalani and Priti Kalani.
Have fun,
-Keith Harris, MCAD
=====================================================
using System;
using System.IO;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
public class SoapDisplayExtension : SoapExtension
{
private Stream originalStream;
private Stream internalStream;
public override object GetInitializer(System.Type serviceType)
{
//not used in this example, but declared abstract in the base
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
//not used in this example, but declared abstract in the base
return null;
}
public override void Initialize(object initializer)
{
//not used in this example, but declared abstract in the base
}
public override Stream ChainStream(Stream stream)
{
originalStream = stream;
internalStream = new MemoryStream();
return internalStream;
}
public override void ProcessMessage(SoapMessage message)
{
if (message.Stage != SoapMessageStage.BeforeDeserialize) return;
CopyStream(originalStream, internalStream);
internalStream.Position = 0;
//copy to a log file
FileStream fs1 = new FileStream(@"C:\Response.log",
FileMode.Append,
FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine("BeforeDeserialize");
sw1.Flush();
CopyStream(internalStream, fs1);
fs1.Close();
internalStream.Position = 0;
}
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)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
}
=====================================================
[quoted text, click to view] "Greg Allen" wrote:
> I have a client that inherits from
> System.Web.Services.Protocols.SoapHttpClientProtocol.
> I create a proxy object and then call one of the web service methods, which
> returns
> an object.
>
> But I'd really like to use the XML of the response, rather than the object.
>
> Is there a way to get this XML that is returned from the web service? Or do
> I have to serialize the object returned?
>
> Thanks,
>
> -- Greg
>
>