I have been in contact with PHP for many years, but I have never been familiar with webService. Recently, my company wants to use PHP as an interface to consider using webService or directly using HTTP requests, so I have read a lot of information about webService over the past two days.
I have been in contact with PHP for many years, but I have never been familiar with webService. Recently, my company wants to use PHP as an interface to consider using webService or directly using HTTP requests, so I have read a lot of information about webService over the past two days.
Below is a small instance
Action. php file content
- //action.php
- Class Action {
- /**
- * Enter description here...
- *
- * @param int $num1
- * @param int $num2
- * @return int
- */
- public function total($num1,$num2){
- return $num1 + $num2;
- }
- }
- ?>
Service. php file content
- //service.php
- require './action.php';
- $server = new SoapServer('./action.wsdl');
- $server->setClass('Action');
- $server->handle();
- ?>
Action. wsdl file content
-
-
- Xmlns: xsd = "http://www.w3.org/2001/XMLSchema"
- Xmlns: soap = "http://schemas.xmlsoap.org/wsdl/soap"
- Xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding"
- Xmlns: wsdl = "http://schemas.xmlsoap.org/wsdl"
- Xmlns = "http://schemas.xmlsoap.org/wsdl/">
-
-
-
-
-
-
-
-
- Enter description here...
-
-
-
-
-
-
-
-
-
Index. php file content
- //index.php
- $test= new SoapClient("http://127.0.0.1/soap2/action.wsdl");
- $result = $test->total(22,1);
- echo $result;
- ?>
Here, index. php is the file that calls the interface, and service. php is the service file of the interface. run index. php to directly obtain the value returned by the interface.