axis and soap from javascript ?

E

Eric Osman

If my question sounds ill-formed, please cut me some slack as I'm just
getting started with this part of the code.

We're trying to do an axis soap interface, that is, talk to a site that
already has a defined "dtd" .

I've already seen some java examples that use SOAP and AXIS to do the
communication.

However, we'd like to communicate from client-side javascript instead of
apache server java.

Do any of you know how to do this ? Or have examples ? Or can point me
to existing packages or examples ?

NOTE: We're already talking to web sites with GET and POST by using
XMLHttpRequest in javascript so is there something like that we can use
to do the SOAP and AXIS kind of communication ?

Thanks. (e-mail address removed) 4/2/2004
 
B

Brian Genisio

Eric said:
If my question sounds ill-formed, please cut me some slack as I'm just
getting started with this part of the code.

We're trying to do an axis soap interface, that is, talk to a site that
already has a defined "dtd" .

I've already seen some java examples that use SOAP and AXIS to do the
communication.

However, we'd like to communicate from client-side javascript instead of
apache server java.

Do any of you know how to do this ? Or have examples ? Or can point me
to existing packages or examples ?

NOTE: We're already talking to web sites with GET and POST by using
XMLHttpRequest in javascript so is there something like that we can use
to do the SOAP and AXIS kind of communication ?

Thanks. (e-mail address removed) 4/2/2004

Do you mean client-side Java, instead of client-side Javascript? I do
not think you can do SOAP communication with javascript alone. You need
at least a plugin.

Brian
 
J

Jim Ley

NOTE: We're already talking to web sites with GET and POST by using
XMLHttpRequest in javascript so is there something like that we can use
to do the SOAP and AXIS kind of communication ?

SOAP is just a pointless XML serialisation of some methods over HTTP,
you have all you need, I would urge you to reconsider, given the
restricted nature of JS client-server communication, there is no point
using a misguided heavyweight system designed for interfacing between
unknown systems when you control both ends (*) Use simple known
methods.

Jim.

(*) To some degree you control the client, you can at least control
the things you intend to send.
 
E

Eric Osman

SOAP is just a pointless XML serialisation of some methods over HTTP,
you have all you need, I would urge you to reconsider, given the
restricted nature of JS client-server communication, there is no point
using a misguided heavyweight system designed for interfacing between
unknown systems when you control both ends (*) Use simple known
methods.


Gee, now I'm glad I included that part about "ill-formed question".

I actually don't really want to use SOAP.

What I do want is the ability to send and receive xml from javascript
and talk to a web service.

It's been suggested to me that I look more into the "msxml" package,
which we have already been using to do XMLHttpRequest, and see what
functions it includes for sending and receiving and parsing xml.

Do you believe I'm on the right track ?

Thanks. /Eric
 
N

news.comcast.giganews.com

It's been suggested to me that I look more into the "msxml" package,
which we have already been using to do XMLHttpRequest, and see what
functions it includes for sending and receiving and parsing xml.

Do you believe I'm on the right track ?

Thanks. /Eric

Eric,

Hi...Here's an example of using Microsoft's implimentation XMLHTTP.
You'll want to do a lot more reading up about it...consider going down
to your local full-service bookstore, or looking for a text on line, or
<gasp/> googling for more info...but this will get you started:

var XMLHTTP = new ActiveXObject( 'Msxml2.XMLHTTP' );

var XMLRequest = new ActiveXObject( 'Msxml2.DOMDocument' );
var XMLResponse;

var method = 'POST';
var async = false;

// TODO: Change the string in the next line to whatever xml you need to
send...
var xmlString ='<root><content>Here is some text</content></root>';

// TODO: Change the next line to the web address of the server you are
// trying to get information from
var url = 'http://localhost/server.asp';

var bSuccessfullyLoaded = XMLRequest.loadXML( xmlString);

if( bSuccessfullyLoaded )
{
debugger;
XMLHTTP.Open( method, url, async );
XMLHTTP.Send( xmlString );
XMLResponse = XMLHTTP.responseXML;

if( 0 == XMLResponse.parseError.errorCode )
{
// TODO: Do something useful here once you
// successfully get a response...
window.alert( XMLResponse.xml );
}
else
{
// TODO: Handle the parsing error here
window.alert('A Parse Error');
}
}


Good Luck!

--Geoff McGrath
 
J

Jim Ley

What I do want is the ability to send and receive xml from javascript
and talk to a web service.

Sending and recieving XML with javascript other than in a reduced
security environment (so you're generally talking web-services) XML
parsing and GET/POST HTTP is available on a number of javascript
capable systems (IE/Mozilla and SVG Clients) it's a lot slower than
parsing other things - JSON being perhaps the most obvious.

Because you control both the client and the server, you don't need to
use the XML benefits.
It's been suggested to me that I look more into the "msxml" package,
which we have already been using to do XMLHttpRequest, and see what
functions it includes for sending and receiving and parsing xml.

Do you believe I'm on the right track ?

you could do it like that, I wouldn't recommend not doing so, it's
very inflexible. Maybe look at http://json-rpc.org/ or similar, but
anything that doesn't use XML parsing will open up the possibilities
considerably, that's the hardest part.

Jim.
 
E

Eric Osman

Well, it looks like I need to put on some special SOAP headers to
successfully talk to the web service.

*** If this is true, do I have to construct those soap headers by
**** hand ? Or is there a javascript library I can use to
**** do it more conveniently ?

If I have to do it by hand, do the following errors help you help me
figure out what I'm doing wrong ?


If I do basically what you show below, the xml I get back looks like
this if I don't put in any SOAP headers:

<?xml version="1.0"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXException: Bad envelope tag:
TEST_REQUEST</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

If I put in a header equivalent to the one that was used for delivering
that error message to me, I get this:

<?xml version="1.0"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXException: SimpleDeserializer encountered a
child element, which is NOT expected, in something it was trying to
deserialize.</faultstring>
<detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>


Any ideas about this ?????

Thanks. /Eric
 
M

mromarkhan

peace be unto you.
Requires ActiveX
<html>
<head>
<title>Webservice without the overhead</title>
<script>
function getSummary(name)
{
var XMLHTTP = new ActiveXObject( 'Msxml2.XMLHTTP' );
var XMLRequest = new ActiveXObject( 'Msxml2.DOMDocument' );
var XMLResponse;
var method = 'POST';
var async = false;
var xmlString ="<?xml version=\'1.0\'?><s:Envelope xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\' xmlns:xsi=\'http://www.w3.org/1999/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/1999/XMLSchema\'><s:Body><m:getTemperature xmlns:m=
var url = 'http://live.capescience.com:80/ccx/AirportWeather';
var bSuccessfullyLoaded = XMLRequest.loadXML( xmlString);
if( bSuccessfullyLoaded )
{
XMLHTTP.Open( method, url, async );
XMLHTTP.setRequestHeader("Content-Type", "text/xml");
XMLHTTP.setRequestHeader("SOAPAction","capeconnect:AirportWeather:Station#getTemperature");
XMLHTTP.Send( xmlString );
XMLResponse = XMLHTTP.responseXML;
if( 0 == XMLResponse.parseError.errorCode )
{
//window.alert(XMLResponse.xml);
var xmlDoc
var root
xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.loadXML(XMLResponse.xml)
root = xmlDoc.documentElement
return root.firstChild.firstChild.firstChild.firstChild.nodeValue;
}
else
{
return "<b>No Data</b>";
}
}
}
</script>
</head>
<body>
Omar Khan lives where
<b>
<script>
document.write(getSummary("CYYZ"));
</script>
</b>
</body>
</html>
<!--
outputs on 2004-April-27
The Temperature at Toronto Pearson Int'L. Ont., Canada is 39 F (4 C)

http://live.capescience.com/wsdl/AirportWeather.wsdl
----------
content type to text/xml
----------
SOAPAction to soapAction attribute of
<operation name="getTemperature">
<soap:eek:peration soapAction="capeconnect:AirportWeather:Station#getTemperature" />
----------
url=
<service>
<port>
<soap:address location="http://live.capescience.com:80/ccx/AirportWeather" />
----------
method name and argument name and data type
<message name="getTemperature">
<part name="arg0" type="xsd:string" />
----------
namespace for method
<operation name="getTemperature">
<soap:eek:peration soapAction="capeconnect:AirportWeather:Station#getTemperature" />
<input>
-->
 
M

mromarkhan

Correction
<html>
<head>
<title>Webservice without the overhead</title>
<script>
function getSummary(name)
{
var XMLHTTP = new ActiveXObject( 'Msxml2.XMLHTTP' );
var XMLRequest = new ActiveXObject( 'Msxml2.DOMDocument' );
var XMLResponse;
var method = 'POST';
var async = false;
var xmlString="<?xml version=\'1.0\'?>"+
"<s:Envelope xmlns:s=\'http://schemas.xmlsoap.org/soap/envelope/\' "+
"xmlns:xsi=\'http://www.w3.org/1999/XMLSchema-instance\' "+
"xmlns:xsd=\'http://www.w3.org/1999/XMLSchema\'>"+
"<s:Body><m:getTemperature "+
"xmlns:m=\'capeconnect:AirportWeather:Station\'>"+
"<arg0 xsi:type=\'xsd:string\'>"+name+"</arg0>"+
"</m:getTemperature></s:Body></s:Envelope>";
var url = 'http://live.capescience.com:80/ccx/AirportWeather';
var bSuccessfullyLoaded = XMLRequest.loadXML( xmlString);
if( bSuccessfullyLoaded )
{
XMLHTTP.Open( method, url, async );
XMLHTTP.setRequestHeader("Content-Type", "text/xml");
XMLHTTP.setRequestHeader("SOAPAction","capeconnect:AirportWeather:"+
"Station#getTemperature");
XMLHTTP.Send( xmlString );
XMLResponse = XMLHTTP.responseXML;
if( 0 == XMLResponse.parseError.errorCode )
{
//window.alert(XMLResponse.xml);
var xmlDoc
var root
xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.loadXML(XMLResponse.xml)
root = xmlDoc.documentElement
return root.firstChild.firstChild.firstChild.firstChild.nodeValue;
}
else
{
return "<b>No Data</b>";
}
}
}
</script>
</head>
<body>
Omar Khan lives where
<b>
<script>
document.write(getSummary("CYYZ"));
</script>
</b>
</body>
</html>
<!--
outputs on 2004-April-27
The Temperature at Toronto Pearson Int'L. Ont., Canada is 39 F (4 C)

http://live.capescience.com/wsdl/AirportWeather.wsdl
----------
content type to text/xml
----------
SOAPAction to soapAction attribute of
<operation name="getTemperature">
<soap:eek:peration soapAction="capeconnect:AirportWeather:Station#getTemperature" />
----------
url=
<service>
<port>
<soap:address location="http://live.capescience.com:80/ccx/AirportWeather" />
----------
method name and argument name and data type
<message name="getTemperature">
<part name="arg0" type="xsd:string" />
----------
namespace for method
<operation name="getTemperature">
<soap:eek:peration soapAction="capeconnect:AirportWeather:Station#getTemperature" />
<input>
-->
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top