PHP SOAP Tutorial

Source: Internet
Author: User
Tags cookie names http authentication soap soap client wsdl

First, SoapServer server

1, __construct
Action: Create a SoapServer object
Usage: __construct (mixed WSDL [, array options])
Parameters: WSDL file address, Options Soap_version,encoding,actor,classmap
Return: Object

2, AddFunction
Function: Export one or more functions for the client
Usage: addfunction (mixed functions)
Parameters: Functions function, one or more, all Soap_functions_all
return: None

3, Getfunctions
function: Get all functions
Usage: getfunctions ()
Parameters: None
Returns: Array of functions

4, SetClass
function: Export all functions in a class
Usage: SetClass (string class_name [, mixed args [, mixed ...])
Parameter: Class_name class name args parameter
return: None

5, Setpersistence
Function: Allows session request data to be saved between PHP
Usage: setpersistence (int mode)
Parameters: Mode soap_persistence_session soap_persistence_request
return: None

6, fault
Function: Allows session request data to be saved between PHP
Usage: Fault (string code, string string [, String actor [, Mixeddetails [, String name]])
Parameter: A code error code string short error message actor causes the wrong string details error detail
return: None

7, handle ([string soap_request])
Function: Processes a SOAP request, invokes the necessary functionality, and sends back a response.
Usage: Handle ([string soap_request])
Parameters: Soap_request Request
return: None

Second, soapclient client

1, __construct
Action: Create a SoapClient object
Usage: __construct (mixed WSDL [, array options])
Parameters: WSDL file address or NULL,
Options
A, soap_version SOAP version, encoding encoding, compression compression, Classmap
B, HTTP authentication: login, password
C, Agent services: Proxy_host, Proxy_port, Proxy_login and Proxy_password
D, certificate verification: Local_cert, passphrase
E, when WSDL is null: location, URI
Return: Object

2, __call
Role: Calling function
Usage: __call (string function_name, array arguments [, array options[, array input_headers [, array output_headers]])
Parameter: function_name,arguments
return: None

3, __dorequest
Role: In executing an HTTP request
Usage: __dorequest (string request, string location, string action,int version [, int one_way])
Parameters: Request XML SOAP request location requested address action, version
Return: String

4, __getfunctions
Function: Get all methods
Usage: __getfunctions ()
Parameters: None
Returns: Array of functions

5, __getfunctions
Function: Get all methods
Usage: __getfunctions ()
Parameters: None
Returns: Array of functions

6, __setcookie
Role: Set Cookies
Usage: __setcookie (string name [, String value])
Parameters: Name cookie names Value cookie values
return: None

7, __getlastrequest
Function: Get the last Request
Usage: __getlastrequest ()
Parameters: None
Back to: Last Request

8, __getlastrequestheaders
Function: Gets the last request header information
Usage: __getlastrequestheaders ()
Parameters: None
return: Last Request header information

9, __getlastresponse
Role: Get the final response
Usage: __getlastrequest ()
Parameters: None
Return: Last Request response

10, __getlastresponseheaders
Function: Get the final response header information
Usage: __getlastresponseheaders ()
Parameters: None
Return: Last response to header information

Three, Soapvar parameters

1, __construct
Action: Create a Soapvar object
Usage: __construct (mixed data, int encoding [, String type_name [, String Type_namespace [, String node_name [, Stringnode_na Mespace]])
Parameters: Data, encoding encoding
Return: Parameter Object

Four, Soapparam parameters

1, __construct
Action: Create a Soapparam object
Usage: __construct (mixed data, string name)
Parameter: The variable passed by data, the value of the name variable
Return: Parameter Object

__construct (string namespace, string name [, mixed data [, bool MustUnderstand [, mixed actor]])

V. SoapHeader Head

1, __construct
Action: Create a Soapheade object
Usage: __construct (string namespace, string name [, mixed data [, bool MustUnderstand [, mixed actor]])
Parameters: Namespace namespace name SOAP header tag names, data header contents
Return: Object

VI. SoapFault Head

1, __construct
Action: Create a SoapFault object
Usage: __construct (string faultcode, String faultstring [, Stringfaultactor [, Mixed detail [, String faultname [, Soapheade Rheaderfault]])
Parameters: FaultCode error code, faultstring error message, Faultactor cause error string, detail error details
Return: Object

Vii. examples

1. Define a class

<?PHPclassCulculator { Public   functionSum$x,$y )           {               return   $x+$y ; }      }      classCulculator { Public functionSum$x,$y)           {               return $x+$y; }      }  ?>

2. Use Zend Studio to generate WSDL files;

3. SOAP Server Side (server.php)

 <? php    require             './culculator.php ' ;        $server  = Newsoapserver ('./wps.wsdl '   $server ->setclass (' culculator '   $server ->handle ();             require  './culculator.php '   $server  = Newsoapserver ('./wps.wsdl '   $server ->setclass (' culculator '   $server ->handle (); ? 

3. SOAP Client (client.php)

<? PHP      $soap  = Newsoapclient ('./wps.wsdl ' );       Echo   $soap ->sum ();       // Run output 3  ? >

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.