PDA

View Full Version : XML.SendAndLoad integration with .Net


Seba
06-07-2005, 03:56 PM
Hi people,

It seams that I can't find a solution for passing a dynamic xml to VisualStudio .Net

In the Flash I have something very simple as:

var xmlIn:XML = new XML();
xmlIn.ignoreWhite = true;
xmlIn.onLoad = myOnLoad;

var xmlOut:XML = new XML("<controles />");

xmlOut.contentType = "text/xml";

var newNode:XMLNode = xmlOut.createElement("CONTROL");
newNode.attributes["tipo"] = este._tipo;
newNode.attributes["nombre"]= este._name;

xmlOut.firstChild.appendChild(newNode);
xmlOut.sendAndLoad("http://domain/MAP/MAP.aspx", xmlIn);
function myOnLoad(success:Boolean)
{
if (success)
{
debug.text = this;
trace ("ANDUVO");
}
else
{
trace("loginFailed");
}
}


I'm quite sure this works. The problem is at the .Net side. It seams that I can't find the way to "read" the XML sent.

Anyone did this before in VisualStudio .Net? I'm using C# but VB will work as well.

Thank you in advance!

Seba
06-08-2005, 07:54 PM
Hi again.

I'm still working on this and made some advances: let me tell you that the swf is embeded into the aspx and hence y need the swf to make a submit on the page containing it in order receive the XML in the aspx. So, I concluded that SendAndLoad does not do a submit. They are made to work with web services or so, which is not the case. So I have to work with the plane Send method of AS in order to get a PostBack in the aspx.

Then, the AS script was modified as:

var xmlOut:XML = new XML("< controles />");

xmlOut.contentType = "text/xml";

var newNode:XMLNode = xmlOut.createElement("CONTROL");
newNode.attributes["tipo"] = este._tipo;
newNode.attributes["nombre"]= este._name;

xmlOut.firstChild.appendChild(newNode);
xmlOut.send("http://localhost/MAP/MAP.aspx", "_self");


This way I send the XML to the aspx page and parse it as follows in C#:

Response.ContentType = "text/xml";
XmlDocument doc = new XmlDocument();

try
{
XmlTextReader reader = new XmlTextReader(Request.InputStream);
doc.Load( reader );
doc.Save(Request.PhysicalApplicationPath + @"Temp\incom.xml");
reader.Close();
}
catch ( Exception ex )
{
string msg = ex.Message;
}


Aleluya! The incom.xml is written and it is ok. However, after the Page_Load event in C#, the aspx tries to show the XML in the page with the following error (which I’ve translated from the Spanish):

The translation would be something like: A literal string was expected but the quotes were not found. Error processing the resource http://localhost/MAP/MAP.aspx. Line 2, Position 63

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

Anyway, I’m quite sure that this is because my crappy code in AS and / or C#. Any clues? Enybody?

Seba
06-09-2005, 02:56 PM
Hi again,

The problem was the following line at the C# code:

Response.ContentType = "text/xml";
That made the whole aspx to become a xml watcher. Without that line the xml is read and written by the aspx without a problem.

So, the only issue now is that using

XML.Send ( "url", "target window") does provides a Submit() but is not as neat as a
XML.SendAndLoad ("webService", "target XML object")
which becomes aware of any updates on the XML. So I have to write down the XML file and read it again from disk at the swf.

So, I still think it is not the best code arround but it delivers. I didn't see anithing like this before in any forum so if there are any programmer more experienced than I who wants to correct my code, he/she will be more than welcome.

Regards.