Hab folgendes Problem
beim Response enthält der ComplexType nur ARRAY
mein Code:
PHP-Code:
<?php
// includes
require_once('./lib/nusoap.php');
require_once("./config/dbconnect.php");
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('xcpService', 'urn:xcpService');
$server->wsdl->addComplexType(
'Category',
'complexType',
'struct',
'all',
'',
array(
'name' => array('name' => 'name', 'type' => 'xsd:string'),
'value' => array('name' => 'value', 'type' => 'xsd:int')
)
);
// Register the method to expose
$server->register('hello', // method name
array('name' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:xcpService', // namespace
'urn:xcpService#hello', // soapaction
'rpc', // style
'encoded', // use
'Says hello to the caller' // documentation
);
$server->register('getCategories', // method name
array('language' => 'xsd:string'), // input parameters
array('return' => 'xsd:Category'), // output parameters
'urn:xcpService', // namespace
'urn:xcpService#getCategories', // soapaction
'rpc', // style
'encoded', // use
'Retruns a List of the Categories' // documentation
);
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
function getCategories($language){
//$categories = array();
//$categories[] = array("name"=>"Teil", "value"=>2);*/
//$categories = "blub";
//return array('Category' => array('name'=>"Auto", 'value'=>1));
return array('name'=>"Auto", 'value'=>1);
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
Die WSDL Datei:
PHP-Code:
<definitions targetNamespace="urn:xcpService"><types><xsd:schema targetNamespace="urn:xcpService"><xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/><xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/><xsd:complexType name="Category"><xsd:all><xsd:element name="name" type="xsd:string"/><xsd:element name="value" type="xsd:int"/></xsd:all></xsd:complexType></xsd:schema></types><message name="helloRequest"><part name="name" type="xsd:string"/></message><message name="helloResponse"><part name="return" type="xsd:string"/></message><message name="getCategoriesRequest"><part name="language" type="xsd:string"/></message><message name="getCategoriesResponse"><part name="return" type="xsd:Category"/></message><portType name="xcpServicePortType"><operation name="hello"><documentation>Says hello to the caller</documentation><input message="tns:helloRequest"/><output message="tns:helloResponse"/></operation><operation name="getCategories"><documentation>Retruns a List of the Categories</documentation><input message="tns:getCategoriesRequest"/><output message="tns:getCategoriesResponse"/></operation></portType><binding name="xcpServiceBinding" type="tns:xcpServicePortType"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="hello"><soap:operation soapAction="urn:xcpService#hello" style="rpc"/><input><soap:body use="encoded" namespace="urn:xcpService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" namespace="urn:xcpService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation><operation name="getCategories"><soap:operation soapAction="urn:xcpService#getCategories" style="rpc"/><input><soap:body use="encoded" namespace="urn:xcpService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input><output><soap:body use="encoded" namespace="urn:xcpService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output></operation></binding><service name="xcpService"><port name="xcpServicePort" binding="tns:xcpServiceBinding"><soap:address location="http://localhost/Xcarsnparts/server.php"/></port></service></definitions>
nun der Client:
PHP-Code:
try {
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SOAPClient('http://localhost/********/server.php?wsdl');
var_dump($client->__getFunctions());
echo $client->hello("test");
echo "<br><br>";
/*foreach($client->getCategories("de") AS $cat){
echo $cat."<br>";
}*/
var_dump($client->getCategories("de"));
ich find einfach nicht meinen Fehler!
hab schon unzählige Beispiele auf Google verglichen...
ich hoff ihr könnt mir schnell helfen