WebService-php-2 (17), webservice-php-17. WebService-php-2 (17), webservice-php-17wsdl instance? Xmlversion1.0encodingUTF-8? DefinitionstargetNamespacelocalhost00xmlns: tnslo WebService-php-2 (17), webservice-php-17
Wsdl instance
Server example:
function test($x) {return $x;}$ss = new SoapServer('http://localhost/00/wsdl.xml');$ss->addFunction('test');$ss->handle();
Client call:
$soap = new soapClient('http://localhost/00/wsdl.xml',array('trace'=>true));var_dump($soap->test('10086'));
Passing and returning array parameters
If the transmitted or returned parameters are arrays, you can describe them in the message label.
XML-RPC call
XML-RPC can be understood as a simplified version of soap, the packaging of data is relatively simple. php. ini, to open extension = php_xmlrpc.dll
/* When calling a function, the rpc server transmits the following parameters: array (0 => 'function name', 1 => array (real parameter 1, real parameter 2 ,... real parameter N), 2 => NULL) */function hello () {return 'hello';} function sum ($ method, $ args, $ extra) {return array_sum ($ args);} // Create an RPC Server $ server = xmlrpc_server_create (); xmlrpc_server_register_method ($ server, 'hello', 'Hello'); xmlrpc_server_register_method, 'sum', 'sum'); // receives a request $ request = $ HTTP_RAW_POST_DATA; // retrieves the execution result after executing the XML request to call the client $ xmlrpc_response = xmlrpc_server_call_method ($ server, $ request, null); // output the result XML after function processing ('content-Type: text/XML'); echo $ xmlrpc_response; // destroy the XML-RPC server-side resource xmlrpc_server_destroy ($ server );
Client:
class rpcclient {protected $url;public function __construct($url='' ) {$this->url = $url;}protected function query($request) {$context = stream_context_create(array('http' => array('method' => "POST",'header' => "Content-Type: text/xml",'content' => $request)));$xml = file_get_contents($this->url, false, $context);return xmlrpc_decode($xml);}public function __call($method , $args) {$request = xmlrpc_encode_request($method , $args);return $this->query($request);}}$rpc = new rpcclient('http://localhost/00/rpcs.php');var_dump($rpc->hello());var_dump($rpc->sum(4,5,6));
Differences between WebService and json APIs
WebService json API
Data encapsulation XML json
High Complexity
The underlying protocol is not limited to HTTP
Data types can be strictly defined and cannot be strictly defined.
Additional API documentation is required for self-explanatory self-instructions
Http://www.bkjia.com/PHPjc/993278.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/993278.htmlTechArticleWebService-php-2 (17), webservice-php-17 wsdl instance? Xml version = '000000' encoding = 'UTF-8 '? DefinitionstargetNamespace = 'http: // localhost/00/'xmlns: tns = 'http: // lo...