PHP 5 Apache 2.2 WebService creation and configuration
Test Tool: Wscaller.jar (This is the webservice that is called for Java programs)
Tip: To run Wscaller.jar to select the install JDK if no JDK is installed, Wscaller.jar will be displayed as a compressed package
1 Write WebService the interface to use
Copy Code code as follows:
<?php
class Service
{
function add ($a, $b) {
$c = $a + $b;
return $c;
}
function str ($string) {
return $string;
}
}
Require (' cls_mysql.php ');
$db = new Cls_mysql (' localhost ', ' root ', ' root ', test_db ');
$db = new Cls_mysql (' 211.103.156.227:3306 ', ' root ', ' txtx ', test_db ');
' TESTWSDL.WSD needs to be followed by a Zend studio build.
$server =new soapserver (' testwsdl.wsdl ', Array (' URI ' => ' http://webserver.com/', ' Encoding ' => ', ' utf-8 '), ' SOAP_ ' Version ' => soap_1_2));
$server->setclass ("service");
$server->handle ();
?>
2. generate wsdl file
In the menu
file--àExport---àphp Select "WSDL file" and the next step (Figure 1)
File name is the location where the WSDL file resides
Exported files The file below is the PHP file (interface file) you just created.
Classes the front of the service below
URL to fill in the interface file access address (such as:http://webserver.com/rpcservice.php)
Click the global settings to show the following figure (Figure 3)
Select rpc–oriented
Then click "OK" to click "Finish"
The following figure appears (Figure 4)
The final step is to give each parameter a reasonable type (the following figure)
And then Save
To this WSDL file has been generated
Access path http://webserver.com/testwsdl.wsdl (the following content will appear )
apache xml
Note: don't use chrome . Open wsdl file , may appear to be abnormal ( ie Firfox can be used )
Tests whether a successful call to the
Testing tools
Wscaller.jar
Note: The JDK must be installed to run Wscaller.jar Please do not unzip Wscaller.jar
If you do not return the information correctly, you can visit your PHP directly to see if it will error
(This example http://webserver.com/rpcservice.php)
PHP to support soap
edit php.ini if PHP version is 5.X
Extension=php_soap.dll ( add if present to remove comment )
Restart Apache
Apache should pay attention to this file mime.types
function to add a new parameter
Find the message name= the " function name " and change the parameters to the parameter name
WSDL file
<!--[endif]-->
Php Interface File
Note:$e is the C parameter in the WSDL file
Add a new function
WSDL to copy code on line ; PHP to write the corresponding function (see the selected part is actually copied the add this function and paste directly below it can) below to add add_bak function as an example
Wsdl
1. copy message label
2. copy the label in the PortType
3. copy binding label content
Php
Copy Code code as follows:
function Add_bak ($a, $b, $e) {
$c = $a + $b-$e;
return $c;
}
Test results
Add_bak function
Add function
Other functions will not test the screenshot.
If there's something wrong, please say thank you.