PHP : Class to create Wsdl with NuSoap
<?php
// in a class ...
/**
* @param string $param
* @return array
*/
public function test_ws($param)
{
return array('response' => "Hello {$param->name}");
}
/**
* @return array
*/
public function get_some_values()
{
return array('values' => array( 'value_str' => 'This is a string.',
'value_int' => 9));
}
/**
* @return array
*/
public function get_more_values()
{
return array('return' =>
array( 'value_bool' => TRUE,
'another_complex' =>
array( array( 'name' => 'obj_01',
'type' => 'OBJECT'),
array( 'name' => 'res_05',
'type' => 'RESOURCE'))));
}
/**
*
*/
public function create_wsdl()
{
$namespace = 'http://example.com/app/uri';
$server = new nusoap_server();
/*
configureWSDL( $serviceName,
$namespace = false,
$endpoint = false,
$style = 'rpc',
$transport = 'http://schemas.xmlsoap.org/soap/http',
$schemaTargetNamespace = false)*/
$server->configureWSDL( 'web_service_name',
$namespace,
self::WSERVICE_URI,
'document');
//---------------------------------------------------------------------
// test_ws - egy bemenet, egy kimenet
$server->register(
'test_ws', // metódus neve
array('name' => 'xsd:string'), // bemenet
array('response' => 'xsd:string'), // kimenet
$namespace,
FALSE, // "soapaction"
'document', // stílus
'literal', // kódolás
'Test function'); // dokumentáció
//---------------------------------------------------------------------
// get_some_values
$server->register(
'get_some_values',
array(),
array('values' => 'tns:values'),
$namespace,
FALSE, 'document', 'literal', 'Get some values');
// values
$server->wsdl->addComplexType(
'values', // name
'complexType', // typeClass: complexType, simpleType, attribute
'struct', // phpType: array, struct (php assoc array)
'sequence', // compositor: all, sequence, choice
'', // restrictionBase e.g.: SOAP-ENC:Array
array
(
'value_str' => array('type' => 'xsd:string'),
'value_int' => array('type' => 'xsd:int'),
)
);
//---------------------------------------------------------------------
// get_more_values
$server->register(
'get_more_values',
array(),
array('return' => 'tns:more_values'),
$namespace,
FALSE, 'document', 'literal', 'Get more values');
// php_type
$server->wsdl->addSimpleType( 'php_type',
'xsd:string',
'SimpleType',
'struct',
array( 'STRING',
'OBJECT',
'RESOURCE',
'...'));
// complex_val
$server->wsdl->addComplexType(
'complex_val',
'complexType',
'struct',
'sequence',
'',
array
(
'name' => array('type' => 'xsd:string'),
'type' => array('type' => 'tns:php_type'),
)
);
// more_values
$server->wsdl->addComplexType(
'more_values',
'complexType',
'struct',
'sequence',
'',
array
(
'value_bool' => array( 'type' => 'xsd:boolean'),
'another_complex' => array( 'type' => 'tns:complex_val',
'minOccurs' => '0',
'maxOccurs' => 'unbounded')
)
);
//---------------------------------------------------------------------
// output:wsdl
header('Content-Type: text/xml;charset=utf-8');
echo $server->wsdl->serialize();
exit(0);
}
# EOF

Processing your request, Please wait....
No Responses to “PHP : Class to create Wsdl with NuSoap”
Comments (Your Comments)
Leave a Reply