最近用gsoap写了一个WS的服务器,用Linux C写客户端非常得心应手,但是该项目还要求在PHP下能够访问该服务器,到网上一搜,还是有不少的。我下载了nusoap,经过试验,写了如下的客户端调用,贴出来分享一下下啦……
<?php
// Pull in the NuSOAP co de
require_on ce('lib/nusoap.php');
// Create the client instance
$client = new soapclient('http://cdev01.xxx.com/tss.wsdl', true);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
//
// Call the SOAP method
$result = $client->call('mkdir', array('id' => 'ss', 'path' => '/tmp/hah', 'mode' => 0755));
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
//print_r($result);
print($result[faultstring]);
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>';
}
}
//Debugging
// 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>';
?>
<?php
// Pull in the NuSOAP co
require_on
// Create the client instance
$client = new soapclient('http://cdev01.xxx.com/tss.wsdl', true);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
//
// Call the SOAP method
$result = $client->call('mkdir', array('id' => 'ss', 'path' => '/tmp/hah', 'mode' => 0755));
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
//print_r($result);
print($result[faultstring]);
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>';
}
}
//Debugging
// 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>';
?>