Jump to content

NuSoap WSDL Help!!!


kenson

Recommended Posts

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:
[CODE]<?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>';
?>[/CODE]

Server:getfile2.php
[CODE]<?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);
?>[/CODE]

Result:
Error -
Response not of type text/xml

Case 2:  Display Hello
Client:
[CODE]<?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>';
?>
[/CODE]

Server:
[CODE]<?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);
?>[/CODE]

Result: Error - XML error parsing SOAP payload on line 2: Invalid document end

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

Thanks in advance. : )
Link to comment
https://forums.phpfreaks.com/topic/28200-nusoap-wsdl-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.