Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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. : )

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:15 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.