Webservice-php-2 (+), WEBSERVICE-PHP-17
WSDL instance
'1.0'encoding ='UTF-8'?><Definitionstargetnamespace='http://localhost/00/'Xmlns:tns='http://localhost/00/'Xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'xmlns:xsd='Http://www.w3.org/2001/XMLSchema'Xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'xmlns='http://schemas.xmlsoap.org/wsdl/'>
"
http://www.w3.org/2001/XMLSchema
"
targetnamespace=
"
http ://localhost/00/
">
'
testrequest
'> "term
" type=
"
xsd:string
" />
'
testresponse
'>
'
value
' type=
'
xsd:st Ring
"/>
'
oplist
'>
'
test
'>
'
tns:testrequest
'/>
'tns:testresponse'/>
'
Cartsoap
'Type=
'
tns:oplist
'>
'
RPC
'
Transport=
'
http://schemas.xmlsoap.org/soap/http
'/>
'
test
'>
'
http://www.cwtservice.cn/newOperation/
'/>
'
encoded
'
namespace=
'
urn:xmethods-delayed-quotes
' encodingstyle= 'http://schemas.xmlsoap.org/soap/encoding/'/>
'
encoded
'
namespace=
'
urn:xmethods-delayed-quotes'encodingstyle= 'http://schemas.xmlsoap.org/soap/encoding/' />
'
shopws
'>
'
cartsoap
' binding=
'
tns:cartsoap c8> '>
'
http://localhost/00/wss.php
'/>
Server-side Example:
function Test ($x) {returnnew soapserver ('http// Localhost/00/wsdl.xml'); $ss->addfunction ('test') ); $ss->handle ();
Client invocation:
new soapclient ('http://localhost/00/wsdl.xml', Array ('Trace '=(True)); Var_dump ($soap->test ('10086'));
Passing and returning array parameters
If the parameter passed or returned is an array, it can be described in the message label.
'
testrequest
'>
'
term ' Type=
"
xsd:arrayofstring
"/>
'
testresponse
'> '
value
"Type="
xsd:arrayofstring"
/>
XML-RPC Call
xml-RPC can be understood as a simplified version of SOAP, and the packaging of the data is relatively concise. PHP.ini, to open extension=php_xmlrpc.dll
/*Summing function Note that when the RPC server invokes a function, the arguments passed are: Array (0=> ' function name ', 1=>array (argument 1, argument 2,... Argument n), 2=>null)*/function Hello () {return 'Hello';} function sum ($method, $args, $extra) {returnarray_sum ($args);}//creating the RPC Server$server =xmlrpc_server_create (); Xmlrpc_server_register_method ($server,'Hello','Hello'); Xmlrpc_server_register_method ($server,'sum','sum');//Collect requests$request =$HTTP _raw_post_data;//get execution results after calling the client's XML request$xmlrpc _response = Xmlrpc_server_call_method ($server, $request,NULL);//output The resulting XML after the function is processedHeader'Content-type:text/xml'); Echo $xmlrpc _response;//destroying XML-RPC server-side ResourcesXmlrpc_server_destroy ($server);
Client:
classrpcclient {protected$url; Publicfunction __construct ($url ='' ) {$ This->url =$url;}protectedfunction 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);returnXmlrpc_decode ($xml);} Publicfunction __call ($method, $args) {$request=xmlrpc_encode_request ($method, $args);return$ This-query ($request);}} $rpc=NewRpcclient ('http://localhost/00/rpcs.php'); Var_dump ($rpc-hello ()); Var_dump ($rpc->sum (4,5,6));
The difference between WebService and the JSON API
WebService JSON API
Data Encapsulation XML JSON
Complexity of the high and low
Underlying protocol unlimited HTTP
Data types can be strictly defined and not strictly defined
Self-explanatory self-explanatory additional API documentation required
http://www.bkjia.com/PHPjc/993278.html www.bkjia.com true http://www.bkjia.com/PHPjc/993278.html techarticle webservice-php-2, webservice-php-17 wsdl instance? xml version = ' 1.0 ' encoding = ' UTF-8 '? Definitionstargetnamespac E = ' http://localhost/00/' xmlns:tns = ' Http://lo ...