kenson Posted November 23, 2006 Share Posted November 23, 2006 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.2PC B (Server) = Win2K Server + Apache 2.059 + PHP4.4.4 + NuSoap 0.7.2Case 1. Get FileClient:[CODE]<?phprequire_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 coderequire_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 functionfunction 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/xmlCase 2: Display HelloClient:[CODE]<?php// Pull in the NuSOAP coderequire_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 faultif ($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 responseecho '<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 messagesecho '<h2>Debug</h2>';echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';?>[/CODE]Server:[CODE]<?php// Pull in the NuSOAP coderequire_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 functionfunction 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 endWhat 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.