access raw xml of soap webservice in Javascript

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

access raw xml of soap webservice in Javascript

#1

Postby dvanhussel » Wed Mar 06, 2013 1:37 pm

Hi,

In the 'Javascript and XML Guide ' in the documentation an example is given of a way to access the XML document which was created by an Ebase XML resource.

Is it possible to do the same with a webservice resource? What I want to do is call the webservice with data from mapped field values and then in JavaScript iterate the xml response document.

As far as I know I cannot use the provide function

Code: Select all

Document getDocument(documentName)
because there is no document on the server after the webservice call.
0 x

Steve
Moderator
Moderator
Posts: 415
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#2

Postby Steve » Wed Mar 06, 2013 3:29 pm

Hi David,

You should be able to call getDocument("") from the JavaScript from version 4.4.3. This supports Web Services too (web services is an extension to the XML).

The example should be exactly the same.

An example:

XML Example response:

Code: Select all

<ns&#58;purchaseOrder xmlns&#58;ns="http&#58;//www.ebasetech.com">
 <items xmlns="http&#58;//www.myshop.com">
	  <item>
		<name>Hairspray</name>
		<price>0.99</price>
		<quantity>3</quantity>
	  </item>
	  <item>
		<name>Shampoo</name>
		<price>1.99</price>
		<quantity>1</quantity>
	  </item>
  </items>
  <name>Fred</name>
  <name>Rachel</name>
</ns&#58;purchaseOrder>

Code: Select all

//call my web service
resources.WS_WEB_SERVICE.call&#40;&#41;;

//get the response document MY_RESPONSE
var response = resources.WS_WEB_SERVICE.getDocument&#40;"MY_RESPONSE"&#41;;

var xmlDoc = new XML&#40;response&#41;;

//navigate the document
for each&#40;var name in xmlDoc.name&#41;
&#123;
	log&#40;"NAME&#58;&#58; " + name.toString&#40;&#41;&#41;;
&#125;


for each&#40;var name in xmlDoc.*&#58;&#58;items.*&#58;&#58;item.*&#58;&#58;name&#41;
&#123;
	log&#40;"ITEM NAME&#58;&#58; " + name.toString&#40;&#41;&#41;;
&#125;


I am confused when you say there is no response document, there should be one, if the web service resource has it configured.

Note that the root element of the XML document starts at the declared XML variable.

Also note that the "*::" before the nodename is a wildcard to match all nodes of that name.

Hope this helps

Steve
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

#3

Postby dvanhussel » Wed Mar 06, 2013 10:37 pm

Hi Steve,

I feel fairly stupid :oops: It was a perfect example of PEBCAK.

Of course there IS a document on ther server, as configured in the Response Body field of the resource. I was under the impression that the

getDocument method requires a document on disk on the server.

Now that I pass the name of the webservice response document, it works as documented.

I blame it to a lack of coffee this afternoon :)

Thanks for your help!

Regards,

David
0 x


Who is online

Users browsing this forum: No registered users and 4 guests