views:

1750

answers:

4

I am using NuSOAP to try to consume a Web Service built in Java. I have this code so far:

<?php
require_once('lib/nusoap.php'); 
$wsdl="http://localhost:8080/HelloWorldWS/sayHiService?WSDL";
$client=new nusoap_client($wsdl, 'wsdl');
$param='John';#array('name'=>'John'); 
echo $client->call('Hey', $param);
unset($client);
?>

but when the web page gets loaded I get a blank page nothing not even in the code and I really don't know why. Am I doing something wrong?

A: 

Yes, you're doing something wrong. It's hard to know what based on a blank page, but I'd start with this line, which doesn't look like valid PHP:

$param='John';#array('name'=>'John');

"#" does not start a comment in PHP; "//" does

If fixing that still results in a blank page, turn on error reporting and/or add more output throughout to see what exactly is happening.

Scott Reynen
'#' also begins a line comment in PHP. It's just not used very often.
Christopher Nadeau
+2  A: 

Don't use NuSoap. PHP has had a native soap client since version 5, which is far more stable, besides being faster.

.. when the web page gets loaded I get a blank page nothing not ..

That's probably a fatal error. Try checking the error logs to see what went wrong. Or set display_errors = on

troelskn
+3  A: 

although NuSOAP is a very common PHP SOAP library, it's main use in PHP4 applications I think. because PHP5 has a built-in SOAP extension that is faster (because it is a compiled extension). I also recommend using Zend Framework SOAP library. but I remember I wanted to use some web service (not written by me, implemented in Java) and none of these SOAP clients worked, but the NuSOAP. and I really could not figure out why.

anyway, here is the thing that I did to use that web service back then:

$soapClient = new nusoap_client($wsdlFile, 'wsdl', '', '', '', '');
$soapClient->soap_defencoding = 'UTF-8';
$soapClient->debug_flag = false;
$soapError = $soapClient->getError();
if (! empty($soapError)) {
    $errorMessage = 'Nusoap object creation failed: ' . $soapError;
    throw new Exception($errorMessage);
}
// calling verifyT method, using 2 parameters.
$tResult = $soapClient->call( 'verifyT', array($param1, $param2) );
$soapError = $soapClient->getError();
if (! empty($soapError)) {
    $errorMessage = 'SOAP method invocation (verifyT) failed: ' . $soapError;
    throw new Exception($errorMessage);
}
if ($soapClient->fault) {
    $fault = "{$soapClient->faultcode}: {$soapClient->faultdetail} ";
    // handle fault situation
}
farzad
+1  A: 

Don't use NuSoap. PHP has had a native soap client since version 5

There are some good reasons to keep using NuSOAP on PHP5 :

  • NuSOAP generate a list of methods when you GET the page
  • NuSOAP generate the WSDL "on the fly" a really useful feature that is not provided by native implementation of SOAP in PHP 5
Pico