all groups > dotnet web services > february 2006 >
You're in the

dotnet web services

group:

Where to find/get XML version of response?


Where to find/get XML version of response? Greg Allen
2/26/2006 3:24:04 PM
dotnet web services:
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

RE: Where to find/get XML version of response? Keith Harris
2/27/2006 12:02:29 PM
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]
Re:Where to find/get XML version of response? linux par
4/2/2006 5:59:26 AM
Configuring Internet Explorer to use proxy server has never been easier:

If you want to configure it from command line, look at:
http://ieproxycfg.50webs.com/index.html
and if you are looking for UI approch, look at:
http://ieproxycfg.50webs.com/proxychain.html

C'ya

AddThis Social Bookmark Button