有在客戶端和服務器文件的代碼中的bug,我已經更新了代碼
server.php
server.php
<?php
require_once ("lib/nusoap.php");
$URL = "https://www.domain.com";
$namespace = $URL . '?wsdl';
$server = new soap_server;
$server->debug_flag = false;
$server->configureWSDL('Test', $namespace);
$server->wsdl->schemaTargetNamespace = $namespace;
function get_message($your_name)
{
if(!$your_name)
{
return new soap_fault('Client','','Put Your Name!');
}
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
$server->register('get_message');
// create HTTP listener
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
client.php
<?php
require_once ("lib/nusoap.php");
$URL = "http://www.domian.com/server.php";
$namespace = $URL . '?wsdl';
$server = new soap_server(); //added()
$server->debug_flag = false;
$server->configureWSDL('Test', $namespace);
//$server->wsdl->schemaTargetNamespace = $namespace;
function get_message($your_name)
{
if(!$your_name)
{
return new soap_fault('Client','','Put Your Name!');
}
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
$server->register('get_message',
array('request' => 'xsd:ArrayReq'), // ArrayReq is type for your parameters
array('return' => 'xsd:String'),
'urn:Test',
'urn:Test#get_message',
'rpc',
'encoded',
'show message'); // added request return array
// create HTTP listener
//$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service(file_get_contents('php://input'));
exit();
?>
客戶端.php
<?php
$wsdl = "http://www.domian.com/server.php?wsdl";
require_once ('lib/nusoap.php');
$param = array("your_name" => "Liam");
$client = new nusoap_client($wsdl); // user nusoap_client() for creating client object
//$client = new SoapClient($wsdl, array("trace" => true));
$response = $client->call('get_message', $param); // use call() to call the server functions
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
echo $response;
}
?>
它的工作!
爲什麼不使用帶有內置SoapClient和SoapServer的PHP Soap擴展?它更快,更少bug,更多功能和大量示例。 – lubosdz 2014-11-04 23:13:00
我試着根據你的建議,但沒有成功。我結束了切換到JSON。我創建的應用程序是相當基本的,客戶端將用.net編寫。我已經閱讀過.net客戶端通過SOAP與PHP服務器進行通信時遇到困難,所以這可能是更好的方法。 – Liam 2014-11-06 18:22:16