[英]How to get the raw xml returned from a webservice request?
你有两个真正的选择。 您可以创建一个SoapExtension,它将插入到响应流中并检索原始XML,或者您可以更改代理存根以使用XmlElement来检索代码中访问的原始值。
对于SoapExtension,您希望在此处查看: http : //www.theserverside.net/tt/articles/showarticle.tss?id = SAPExtensions
对于XmlElement,您需要查看此处: http : //www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.webservices/2006-09/msg00028.html
所以,这就是我最终做到的方式。 场景是用户单击按钮并希望查看Web服务返回的原始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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.