Php5 apache 2.2 webservice creation and configuration of of Java
- 2020-03-31 21:32:13
- OfStack
Test tool: wscaller.jar (this article is a webservice called for a Java program)
Tip: to run wscaller. jar choose to install the JDK. If the JDK is not installed, the wscaller. jar will appear as a compressed package
Write the interface for the webservice
<?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 generated later using Zend Studio.
$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 the WSDL file
The menu
The File - aExport - aphp Select "WSDL file" and then next step (figure 1)
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223939129.png" >
The File name is the location of the WSDL File
The following file is the PHP file that you just created above (the interface file)
I'm going to put a check in front of the service under Classes
Fill in the URL interface file access address (such as: (link: http://webserver.com/rpcservice.php)
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223939420.jpg" >
Click on global Settings to see the following image (figure 3)
Select the RPC actor Oriented
Then click "ok" Click "Finish"
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223939644.jpg" >
See figure 4 below)
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223939521.jpg" >
The final step is to give each parameter a reasonable type (figure below)
Then save
The WSDL file has been generated
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223939298.jpg" >
Access path (link: http://webserver.com/testwsdl.wsdl) (the following will appear.)
Note: do not open the WSDL file with chrome, it may appear abnormal (ie firfox can be used)
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940568.jpg" >
Test whether it can be successfully invoked
Testing tools
WsCaller. Jar
Note: the JDK must be installed to run wscaller. jar ; Please do not unzip the wscaller. jar
If you can't return the information correctly, you can directly access your PHP to see if you can't report an error
(in this case (link: http://webserver.com/rpcservice.php)
If the PHP version is 5.x, edit php.ini
The extension = php_soap. Dll (add without comment if it exists)
Restart apache
Apache will take note of this file mime.types
The < img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940331.jpg" >
The function adds a new parameter
Find message name= "function name" & PI; Directly copy and change the parameter name
WSDL file
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940932.jpg" >
< ! -- [endif] -- >
Php interface file
The < code > 1 < / code > < code > function < / code > < code > add (< / code > < code > $a < / code > < code >, < / code > < code > $b < / code > < code >, < / code > < code > $e < / code > < code >) {< / code > The < code > 2 < / code > The < code > < / code > < code > $c < / code > < code > = < / code > < code > $a < / code > < code > + < / code > < code > $b < / code > < code > + < / code > < code > $e < / code > < code >; < / code > The < code > 3 < / code > The < code > < / code > < code > return < / code > < code > $c < / code > < code >; < / code > The < code > 4 < / code > The < code >} < / code >Note: $e is the c parameter & PI in the WSDL file;
Add a new function
WSDL copy code line; PHP writes the corresponding function (see the selected part is simply a copy of the add function and paste it under it) & PI; Let's take the example of adding the add_bak function
WSDL
1. Copy the message tag
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940156.jpg" >
2. Copy the label in the portType
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940572.jpg" >
3. Copy the binding tag content
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940772.jpg" >
PHP
function add_bak($a,$b,$e){
$c=$a+$b-$e;
return $c;
}
The test results
Add_bak function
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940958.jpg" >
The add function
< img border = 0 SRC = "http://files.jb51.net/upload/201101/20110127223940951.jpg" >
Other functions do not test the screenshot
If there is anything wrong, please point it out. Thank you