Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nuSOAP client/server trouble

Status
Not open for further replies.

tswitz00

IS-IT--Management
Jan 26, 2005
67
US
I am trying to write a webservice to consume an xml data string and I am having a little trouble, thought I would post my code here and see if any one had any ideas.

the server method is supposed to accept a XML string and then parse the data and do what ever with it. Well I can make the method call from my client and the request looks ok but I cant seem to get the xml string to show up so I can parse it.

//Server code
Code:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('hellowsdl2', 'urn:hellowsdl2');
// Register the data structures used by the service
$server->wsdl->addComplexType(
    'xmlString',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'firstname' => array('name' => 'firstname', 'type' => 'xsd:string')
    )
);

// Register the method to expose
$server->register('ServicesRequest',                    // method name
    array('xmlData' => 'tns:xmlString'),          // input parameters
    array('return' => 'xsd:string'),    // output parameters
    'urn:hellowsdl2',                         // namespace
    'urn:hellowsdl2#hello',                   // soapaction
    'rpc',                                    // style
    'encoded',                                // use
    ''        // documentation
);
// Define the method as a PHP function
function ServicesRequest($person) {
 	//parse xml
	
	return "".$person['firstname'];  //returns xml string to test if recieved ok. 
	
	
	
}
// 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);
?>

//client code
Code:
<?php
// Pull in the NuSOAP code
require_once('nusoap.php');
// Create the client instance
$client = new soapclient('serverurl.com/testserver.php?wsdl', true);
// 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
$person = array('firstname' => '<First Sal="MR" />firstname</First>');
$result = $client->call('ServicesRequest', array('person' => $person));
// 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>';
    }
}
echo "this is".$result;
// 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>';
?>

This is the actual xml I am trying to consume if you have any thoughts on a better method.

Code:
<?xml version="1.0"?>
<Order id="" un="" pw="">
                        <Person FirstName="" LastName="" SSN="" MaritalStatus="" BirthDate="" Age=""/>
                        <Phone PhoneType="" AreaCode="" Exchange="" Number="" Extension=""/>
                        <Email EmailType="" EmailAddress=""/>
</Order>
 
Is the server script invoked at all?
I wrote a server with nuSOAP a couple of years ago, so I don't recall too many details. A bit more description what happens would be helpful.
Is anything revceived by the server script?
WHat have you done to troubleshoot so far?
 
I actually got it figued out. Thanks though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top