[英]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.