How to get a raw XML request returned from a web service request?

Does anyone know of a simple way to get the raw xml that is returned from a web service request?

I saw a way to do this using Web Services Enhancements , but I don't want the added dependency.

+3
source share
2 answers

You have two real options. You can create a SoapExtension that will be inserted into the response stream and retrieve the raw XML, or you can change your proxies to use the XmlElement to get the raw values ​​for access in the code.

SoapExtension : http://www.theserverside.net/tt/articles/showarticle.tss?id=SOAPExtensions

XmlElement : http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.webservices/2006-09/msg00028.html

+3

, . , XML, -. . xslt . , XML.

        // Calling the webservice
        com.fake.exampleWebservice bs = new com.fake.exampleWebservice();
        string[] foo = bs.DummyMethod();

        // Serializing the returned object
        System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(foo.GetType());
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        x.Serialize(ms, foo);
        ms.Position = 0;

        // Getting rid of the annoying namespaces - optional
        System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument(ms);
        System.Xml.Xsl.XslCompiledTransform xct = new System.Xml.Xsl.XslCompiledTransform();
        xct.Load(Server.MapPath("RemoveNamespace.xslt"));
        ms = new System.IO.MemoryStream();
        xct.Transform(doc, null, ms);

        // Outputting to client
        byte[] byteArray = ms.ToArray();
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=results.xml");
        Response.AddHeader("Content-Length", byteArray.Length.ToString());
        Response.ContentType = "text/xml";
        Response.BinaryWrite(byteArray);
        Response.End();
+3

All Articles