Initial knowledge of PHP soap learning process of excerpt, easy to read later

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

SOAP Simple Object Access Protocol,

WebService three elements, SOAP, WSDL (WebServicesDescriptionLanguage), UDDI (Universal descriptiondiscoveryand Integration, soap is used to describe the format in which the information is passed, the WSDL Used to describe how to access specific interfaces, UDDI is used to manage, distribute, and query webservice.

First, set up a server environment.
Modify PHP.ini
To add extension=php_soap.dll (load soap built-in package)
Modify Soap.wsdl_cache_enabled=1 to soap.wsdl_cache_enabled=0 this is the SOAP cache, the test is best to change to 0, on-line stable changed to 1 soap has two modes one is WSDL, One is no-wsdl two, familiar with several functions

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 [, Mixed details [, 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 [, String Node_ Namespace]])
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 [, String faultactor [, Mixed detail [, String faultname [, Soaphead ER Headerfault]])
Parameters: FaultCode error code, faultstring error message, Faultactor cause error string, detail error details
Return: Object

Vii. examples

1. Define a class

Class Calculator
{
Public function sum ($x, $y)
{
return $x + $y;
}
}
2. Use Zend Studio to generate WSDL files;

3. SOAP Server Side (server.php)

Require './calculator.php ';

$server = Newsoapserver ('./wps.wsdl ');
$server->setclass (' culculator ');
$server->handle ();
3. SOAP Client (client.php)

View source Copy to Clipboard printing help
$soap = Newsoapclient ('./wps.wsdl ');
echo $soap->sum ();
Run Output 3

Initial knowledge of PHP soap learning process of excerpt, easy to read later

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.