有沒有人知道一個簡單的方法來獲取從查詢Web服務返回的原始XML?如何獲取從web服務請求返回的原始xml?
我已經看到了通過Web Services Enhancements這樣做的一種方法,但我不想添加依賴項。
有沒有人知道一個簡單的方法來獲取從查詢Web服務返回的原始XML?如何獲取從web服務請求返回的原始xml?
我已經看到了通過Web Services Enhancements這樣做的一種方法,但我不想添加依賴項。
你有兩個真正的選擇。您可以創建一個SoapExtension,將其插入到響應流中並檢索原始XML,或者可以更改代理存根以使用XmlElement檢索代碼中訪問的原始值。
有關的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
所以,這裏是我最後做的方式。這種情況是,用戶點擊一個按鈕,並希望看到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();
我說得對不對的理解是你被反序列化對象和序列化回,即它不是由服務返回的原始XML數據? – 2011-02-09 08:29:59