Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XmlSerializer
Message
From
31/05/2005 09:51:21
 
 
To
27/05/2005 18:51:25
General information
Forum:
ASP.NET
Category:
XML
Title:
Miscellaneous
Thread ID:
01018060
Message ID:
01018690
Views:
13
Has anyone got any idea on why this isn't working? In particular the following:
// Call transform method and pass on the stream acquired from GetRequestStream()
myXslTransform.Transform(myXPathDocument, null, streamWriter, null);
*********************
System.Net.WebRequest req = System.Net.WebRequest.Create(RemoteServiceURL);
req.Method = "POST";
req.ContentType = "text/xml";
// Get the request stream to write to
System.IO.Stream streamWriter = (System.IO.Stream) req.GetRequestStream();

System.Xml.Serialization.XmlSerializer xmltrans = new System.Xml.Serialization.XmlSerializer(typeof(PaymentContainer));

// Create memory stream for Payment object serialization
MemoryStream memStream = new MemoryStream();

// Serialize using the memStream
xmltrans.Serialize(memStream ,Payment);
memStream.Seek(0, SeekOrigin.Begin);

//Create XPath document for XML transformation
XPathDocument myXPathDocument = new XPathDocument(memStream);
XslTransform myXslTransform = new XslTransform();

// Load XSLT for transformation
string xsltDoc = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
xsltDoc = xsltDoc.Replace("/","\\");
xsltDoc += "PaymentSerialize.xsl";
myXslTransform.Load(xsltDoc);

// IDEALLY, AT THIS POINT THIS SHOULD DO THE TRICK
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxslxsltransformclasstransformtopic16.asp
// Call transform method and pass on the stream acquired from GetRequestStream()
myXslTransform.Transform(myXPathDocument, null, streamWriter, null);

//but this doesn't work (no error, though) so I'll wait with closing the stream
//streamWriter.close();

//test the serialization of object by serializing and writing it to disk
string xsltTestDoc = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
xsltTestDoc = xsltTestDoc.Replace("/","\\");
xsltTestDoc += "PaymentSerializeTestDoc.xml";
XmlTextWriter xwriter = new XmlTextWriter(xsltTestDoc , null);
myXslTransform.Transform(myXPathDocument, null, xwriter, null);
xwriter.Close();
// Data in test XML document looks fine


// Tried also with MemoryStream
MemoryStream memStreamToSend = new MemoryStream();
myXslTransform.Transform(myXPathDocument, null, memStreamToSend, null);
memStreamToSend.Seek(0, SeekOrigin.Begin);

// read the contents of the stream and write them manually to the http
byte[] byteArray = new byte[memStreamToSend.Length];
int count = memStreamToSend.Read(byteArray, 0, (int) memStreamToSend.Length);
UnicodeEncoding uniEncoding = new UnicodeEncoding();
char[] charArray = new char[uniEncoding.GetCharCount(byteArray, 0, count)];
streamWriter.Write(byteArray, 0, byteArray.Length);

// litte examining of the stream shows it has length=533 but all bytes are ''

streamWriter.Close();
System.Net.WebResponse response = req.GetResponse();

StreamReader streamR = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string xmlString = streamR.ReadToEnd().Trim();

// need to transform the XML response before deserializing

PaymentContainer PaymentReceipt = (PaymentContainer) xmltrans.Deserialize(response.GetResponseStream());
Danijel
Previous
Reply
Map
View

Click here to load this message in the networking platform