nawash
07 May 2009, 06:25 PM
Hi,
I am quite new to the AJAX and SOAP (Mr Clean is missing...) technologies.
I use a wrapper of XMLHTTPequest in a case which the web service is located on a server different than the web pages.
I use a php proxy.
The wrapper first gets the WSDL and then make the actual call to the ws.
Everthing is ok with the first call but for the second call instead of having the responseXML field filled, only the reponseText is filled.
Instead of getting the soap result I get an HTML page.
The alert in the web page shows "null"
why ?
everything seems to be ok, I have tried several proxies the xmlhttprequest call seems ok... I am out of tricks here.
Wireshark report a GET instead of a POST for the second call, I have no idea why ...
The code below :
index6.html
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>JavaScript SOAP Client</title>
<script type="text/javascript" src="soapclient.js"></script>
<script type="text/javascript">
//var url = document.location.href.replace("http://localhost/soap_ws_call_test/index6.html","martinproxy.php?url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx");
//var url = "martinproxy.php?url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
//var url = 'yproxy.php?' + encodeURI("http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx");
//var url = "http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
//var url = "http://www.devoxyz.com/test/soap_ws_call_test/proxy.php?proxy_url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
//var path = 'articoli/javascript-soap-client/demo/webservicedemo.asmx';
var path = 'webservice/helloworld.asmx';
var url = 'http://localhost/soap_ws_call_test/yaproxy.php?yws_path=' +encodeURIComponent(path);
function HelloWorld()
{
var pl = new SOAPClientParameters();
SOAPClient.invoke(url, "HelloWorld", pl, true, HelloWorld_callBack);
}
function HelloWorld_callBack(r)
{
alert(r);
}
</script>
</head>
<body>
<form id="frmDemo" name="frmDemo" action="" method="post">
<input type="button" value="Make request" onclick="HelloWorld();" />
</form>
</body>
</html>
</code>
yaproxy.php
<code>
<?php
// PHP Proxy example for Yahoo! Web services.
// Responds to both HTTP GET and POST requests
//
// Author: Jason Levitt
// December 7th, 2005
//
// Allowed hostname (api.local and api.travel are also possible here)
define ('HOSTNAME', 'http://viium.com/');
// Get the REST call path from the AJAX application
// Is it a POST or a GET?
$path = ($_POST['yws_path']) ? $_POST['yws_path'] : $_GET['yws_path'];
$url = HOSTNAME.$path;
// Open the Curl session
$session = curl_init($url);
// If it's a POST, put the POST data in the body
if ($_POST['yws_path']) {
$postvars = '';
while ($element = current($_POST)) {
$postvars .= key($_POST).'='.$element.'&';
next($_POST);
}
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}
// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$xml = curl_exec($session);
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");
echo $xml;
curl_close($session);
?>
</code>
soapclient.js can be found at
http://www.guru4.net/articoli/javascript-soap-client/demo/soapclient.js
I am quite new to the AJAX and SOAP (Mr Clean is missing...) technologies.
I use a wrapper of XMLHTTPequest in a case which the web service is located on a server different than the web pages.
I use a php proxy.
The wrapper first gets the WSDL and then make the actual call to the ws.
Everthing is ok with the first call but for the second call instead of having the responseXML field filled, only the reponseText is filled.
Instead of getting the soap result I get an HTML page.
The alert in the web page shows "null"
why ?
everything seems to be ok, I have tried several proxies the xmlhttprequest call seems ok... I am out of tricks here.
Wireshark report a GET instead of a POST for the second call, I have no idea why ...
The code below :
index6.html
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>JavaScript SOAP Client</title>
<script type="text/javascript" src="soapclient.js"></script>
<script type="text/javascript">
//var url = document.location.href.replace("http://localhost/soap_ws_call_test/index6.html","martinproxy.php?url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx");
//var url = "martinproxy.php?url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
//var url = 'yproxy.php?' + encodeURI("http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx");
//var url = "http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
//var url = "http://www.devoxyz.com/test/soap_ws_call_test/proxy.php?proxy_url=http://www.guru4.net/articoli/javascript-soap-client/demo/webservicedemo.asmx";
//var path = 'articoli/javascript-soap-client/demo/webservicedemo.asmx';
var path = 'webservice/helloworld.asmx';
var url = 'http://localhost/soap_ws_call_test/yaproxy.php?yws_path=' +encodeURIComponent(path);
function HelloWorld()
{
var pl = new SOAPClientParameters();
SOAPClient.invoke(url, "HelloWorld", pl, true, HelloWorld_callBack);
}
function HelloWorld_callBack(r)
{
alert(r);
}
</script>
</head>
<body>
<form id="frmDemo" name="frmDemo" action="" method="post">
<input type="button" value="Make request" onclick="HelloWorld();" />
</form>
</body>
</html>
</code>
yaproxy.php
<code>
<?php
// PHP Proxy example for Yahoo! Web services.
// Responds to both HTTP GET and POST requests
//
// Author: Jason Levitt
// December 7th, 2005
//
// Allowed hostname (api.local and api.travel are also possible here)
define ('HOSTNAME', 'http://viium.com/');
// Get the REST call path from the AJAX application
// Is it a POST or a GET?
$path = ($_POST['yws_path']) ? $_POST['yws_path'] : $_GET['yws_path'];
$url = HOSTNAME.$path;
// Open the Curl session
$session = curl_init($url);
// If it's a POST, put the POST data in the body
if ($_POST['yws_path']) {
$postvars = '';
while ($element = current($_POST)) {
$postvars .= key($_POST).'='.$element.'&';
next($_POST);
}
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}
// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$xml = curl_exec($session);
// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");
echo $xml;
curl_close($session);
?>
</code>
soapclient.js can be found at
http://www.guru4.net/articoli/javascript-soap-client/demo/soapclient.js