Webservice-php-2 (17)

Source: Internet
Author: User
Tags soap wsdl
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

The above describes the Webservice-php-2 (17), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.