If you want to return a custom object array from a nusoap webservice, you have to cast the objects to arrays like so:
<?php
$users = array();
while($res = $db_obj->fetch_row())
{
$user = new user();
$user->Id = $res['id'];
$user->Username = $res['username'];
$user->Email = $res['email'];
$users[] = (array) $user;
}
return ($users);
?>
SoapServer クラス
導入
SoapServer クラスは » SOAP 1.1 および » SOAP 1.2 プロトコル用のサーバとなります。 WSDL サービス記述を使用することもしないこともできます。
クラス概要
SoapServer
{
/* メソッド */
public void fault
( string $code
, string $string
[, string $actor
[, string $details
[, string $name
]]] )
}目次
- SoapServer::addFunction — SOAP リクエストによって処理される単一もしくはいくつかの関数を追加する
- SoapServer::addSoapHeader — SOAP ヘッダをレスポンスに追加する
- SoapServer::__construct — SoapServer コンストラクタ
- SoapServer::fault — エラーを示す SoapServer フォールト を発行する
- SoapServer::getFunctions — 定義されている関数の一覧を返す
- SoapServer::handle — SOAP リクエストを処理する
- SoapServer::setClass — SOAP リクエストを処理するクラスを設定する
- SoapServer::setObject — SOAP リクエストの処理に使用するオブジェクトを設定する
- SoapServer::setPersistence — SoapServer の持続モードを設定する
- SoapServer::SoapServer — SoapServer コンストラクタ
SoapServer
mikkel at nsales dot dk
02-Jun-2010 10:15
02-Jun-2010 10:15
junk2cm at gmx dot de
25-May-2010 07:54
25-May-2010 07:54
As the SoapServer class lacks the possibility of dealing with SOAP-Headers, my following workaround is suitable to my needs when I had to do authentication via the SOAP-Headers:
1. Use a class which handles SOAP requests and let the constructor of this class take the sent headers.
2. Before invoking the SoapServer extract the SOAP-Header from the incoming raw data.
3. When using setClass pass the extracted header to the handling class.
In Your Server-Skript do things like this
<?php
$hdr = file_get_contents("php://input");
if (strpos($hdr,'<s:Header>')===false) {
$hdr = null;
} else {
$hdr = explode('<s:Header>',$hdr);
$hdr = explode('</s:Header>',$hdr[1]);
$hdr = $hdr[0];
}
$srv = new SoapServer('Your_wsdl');
$srv->setClass("ServiceClass",$hdr);
$srv->handle();
?>
And the service class is like this:
<?php
class ServiceClass {
var $IsAuthenticated;
function __construct($hdr) {
$this->IsAuthenticated = false;
if ($hdr!=null) {
$this->header = simplexml_load_string($hdr);
//Your authentication stuff goes here...
}
}
function SomeFunctionOfTheService($a) {
if ($this->IsAuthenticated) {
//here Your function...
}
}
}
?>
carlos dot vini at gmail dot com
20-May-2010 08:55
20-May-2010 08:55
SoapServer does not support WSDL with literal/document. I have a class:
<?php
class My_Soap {
/**
* Returns Hello World.
*
* @param string $world
* @return string
*/
public function getInterAdmins($world) {
return 'hello' . $world;
}
}
?>
To fix this I had to create proxy class:
<?php
class My_Soap_LiteralDocumentProxy {
public function __call($methodName, $args) {
$soapClass = new My_Soap();
$result = call_user_func_array(array($soapClass, $methodName), $args[0]);
return array($methodName . 'Result' => $result);
}
}
?>
Now make sure that the WSDL is created using My_Soap. And that the Server is created using My_Soap_LiteralDocumentProxy:
<?php
if (isset($_GET['wsdl'])) {
$wsdl = new Zend_Soap_AutoDiscover(); // It generates the WSDL
$wsdl->setOperationBodyStyle(array(
'use' => 'literal'
));
$wsdl->setBindingStyle(array(
'style' => 'document'
));
$wsdl->setClass('My_Soap');
$wsdl->handle();
} else {
$server = new Zend_Soap_Server('http://localhost/something/webservice.php?wsdl');
$server->setClass('My_Soap_LiteralDocumentProxy');
$server->handle();
}
?>
dsubar at interna dot com
26-Dec-2009 05:49
26-Dec-2009 05:49
Do not put a SoapServer and a SoapClient in the same PHP file. This seems to cause arbitrary behavior. On the PHP interpreter in Eclipse, everything worked fine. Under MAMP, I got an undocumented error. In moving the client from the same file as the server, everything worked fine.
