Jump to content


NuSoap WSDL HELP!!!


  • You cannot reply to this topic
No replies to this topic

#1 kenson

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 23 November 2006 - 05:59 AM

Dear All,

I am the first time to using NuSoap to create PHP webservices between two terminal.
PC A (Client) = WinXP Prof + Apache 2.059 + PHP5 + NuSoap 0.7.2
PC B (Server) = Win2K Server + Apache 2.059 + PHP4.4.4 + NuSoap 0.7.2

Case 1. Get File
Client:
<?php
require_once('lib/nusoap.php');
$client = new soapclient('http://192.168.2.14/NuSoap/getfile2.php?wsdl');
$err = $client->getError();
if ($err) {
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $client->call('getFile', array('filename' => 'getfile2.php'));
if ($client->fault) {
	echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>';
} else {
	$err = $client->getError();
	if ($err) {
		echo '<h2>Error</h2><pre>' . $err . '</pre>';
	} else {
		echo '<h2>Result</h2><pre>' . htmlspecialchars($result, ENT_QUOTES) . '</pre>';
	}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

Server:getfile2.php
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
print_r($HTTP_SERVER_VARS);
// Create the server instance
$server = new soap_server('getfile2.wsdl');

// Define the method specified in the WSDL as a PHP function
function getFile($filename) {
	global $HTTP_SERVER_VARS;
	if ($filename != 'php.gif' && $filename != 'getfile2.php') {
		return new soap_fault('SOAP-ENV:Client', 'getfile2', 'Unsupported file name', array('filename' => $filename));
	}
	$handle = fopen(dirname($HTTP_SERVER_VARS['PATH_TRANSLATED']) . '/' . $filename, "rb");
	$contents = fread($handle, filesize($filename));
	fclose($handle);
	return base64_encode($contents);
}

// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

Result:
Error -
Response not of type text/xml

Case 2:  Display Hello
Client:
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('http://192.168.2.14/NuSoap/hellowsdl.php?wsdl');
// Check for an error
$err = $client->getError();
if ($err) {
	// Display the error
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
	// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Scott'));
// Check for a fault
if ($client->fault) {
	echo '<h2>Fault</h2><pre>';
	print_r($result);
	echo '</pre>';
} else {
	// Check for errors
	$err = $client->getError();
	if ($err) {
		// Display the error
		echo '<h2>Error</h2><pre>' . $err . '</pre>';
	} else {
		// Display the result
		echo '<h2>Result</h2><pre>';
		print_r($result);
	echo '</pre>';
	}
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

Server:
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('hellowsdl', 'urn:hellowsdl');
// Register the method to expose
$server->register('hello',				// method name
	array('name' => 'xsd:string'),		// input parameters
	array('return' => 'xsd:string'),	// output parameters
	'urn:hellowsdl',					// namespace
	'urn:hellowsdl#hello',				// soapaction
	'rpc',								// style
	'encoded',							// use
	'Says hello to the caller'			// documentation
);
// Define the method as a PHP function
function hello($name) {
        return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

Result: Error - XML error parsing SOAP payload on line 2: Invalid document end
Note:
if we remove ?wsdl from client script -> $client = new soapclient('http://192.168.2.14/NuSoap/hellowsdl.php?wsdl'); and
remove the line $server->configureWSDL('hellowsdl', 'urn:hellowsdl'); in server script. Then this webservices work fine.


What is the possible issue to cause error above two cases?

Thanks in advance. : )





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users