PDA

View Full Version : Xml request help



fshort
21 Jun 2007, 6:13 PM
Hi,
Fairly new to ext. Does anyone have a code sample on how to submit an SOAP/XML request to a soap service and process the xml response? Hunted around the docs/examples and couldn't find an example of this.

Any help would be appreciated.

Thanks,
Fred

resmond
20 Dec 2007, 1:16 PM
I just posted a similar request within another post, but then saw something that LOOKS like an answer, but I suspect isn't.

This is a config option for the request call of the Ext.commection object...

xmlData {Object} (Optional) XML document to use for the post. Note: This will be used instead of params for the post data. Any params will be appended to the URL.

If I understand this correctly, this would un-package the XML data and add it to the URL in post request. What I understand that you need to do to make a classic SOAP request is to put your request parameters into a XML document and place the document into the body of the POST request... NOT at the end of the URL.

The XML file passed to the server is called an envelop and its basic structure(as opposed to its exact schema) is defined by the W3C and looks something like this:

?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Request xmlns="http://www.comany.com/appapi/1.0">
<Parameter>Value</Parameter>
<Parameter>Value</Parameter>
</Request>
</soap:Body>
</soap:Envelope>

Placing your incoming(client-to-server) data within the body of the post request allows a much larger data set to be sent to the server and allows the XML parameter information to be validated against a schema during development or whenever you want to do strict enforcement of calling conventions... such as when the SOAP calls represent a publicly available API.

I do think that some SOAP servers offer configuration options that make the SOAP methods available through alternative calling conventions... such as accepting calls who's parameters are all placed within the URL, but I believe this is a deviation from the accepted standard. It would certainly cost you much of the advantages of using SOAP in the first place.

But the answer would seem to be pretty simple.... find a way to pass a string into the Ext.connection's request function that would be sent as the body of the POST request that is sent from the client to the server. It would seem that the connection object would have something like this since it says it supports the POST method... why support POST instead of GET if you can't put anything in the body of the message.

resmond
20 Dec 2007, 2:25 PM
I had found where the xmlData object is used in the Ext.connection.request... which I believe it would be used to populate the url parameter fields... which is not what SOAP calls for.

Here's what I found happens in Ext.Ajax.request() if you pass in an xmlData object...

1) Ext.Ajax.request() checks for xmlData and sets up the options object to specify the 'Content-Type' header to 'text/xml' and then passes the xmlData object to Ext.Ajax.asyncRequest() as the postData parameter.

2) Ext.Ajax.asyncRequest calls getConnectionObject which calls createXhrObject() which does some browser sniffing to return a connection object that raps the native XmlHttpRequest() object.

3) Ext.AJax.asyncRequest then sets up the POST requests headers using the previously setup options object, which would specify XML to be sent to the server.

4) then it calls XmlHttpRequest().send to send whatever data is represented in the xmlData object to the server in the body of a POST request.

Now I checked the documentation for the XmlHttpRequest().send function and found out that there are two valid ways (supported on all reasonably recent browsers) of passing the outgoing XML to this function:

xmlData = a string containing the text of the complete XML request envelope

xmlData = a DOM document object created with the document.implementation.createDocument() function and then populated with the appropriate XML elements...

I am new to Ext, so I don't know the right Ext wrappers to best create the right kind of Dom object, but I am sure that is not all that difficult. But building the request XML as a string sounds like the easiest solution anyway. I am going to give this a try and post what I find out...