Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2006, 02:03 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default NuSoap WSDL help!!!

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>';
?>
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);
?>
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>';
?>
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);
?>
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. : )





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with nuSoap snowbydave1 Pro PHP 1 August 26th, 2010 08:10 AM
Consuming Web service with NuSoap CraigWhitfield PHP How-To 0 February 27th, 2008 11:20 AM
NuSOAP Help : XML error parsing WSDL on line 2 Odys PHP How-To 0 March 16th, 2007 04:11 PM
nusoap and require_once garbiner PHP How-To 1 May 29th, 2005 04:20 PM
WSDL Reader: Loading of the WSDL file failed. Anil .NET Web Services 0 January 23rd, 2004 02:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.