Home > Backend Development > PHP Tutorial > php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

WBOY
Release: 2016-07-21 15:32:42
Original
821 people have browsed it

php 5 apache 2.2 webservice creation and configuration
Test tool: wsCaller.jar (this article is for webservice called by java program)
Tip: To run wsCaller.jar, you must choose to install jdk. If jdk is not installed, then wsCaller.jar It will be displayed in the form of a compressed package
1 The interface used to write webservice

Copy the code The code is as follows:

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.生成wsdl文件

菜单中

File--àExport---àphp    选中 “wsdl file” 然后下一步 (图1

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

File name wsdl 文件所在的位置

Exported files 下面的文件是你上面刚刚创建的php文件(接口文件)

Classes 下面的service 前面的勾要打上

URL 中填写接口文件的访问地址 (如:http://webserver.com/rpcservice.php

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

点击global settings 出现下图(图3

选择RPC – Oriented

然后点击 ok  在点击 “Finish”

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

出现下图(图4

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

最后一步就是给 每个参数一个合理的类型(下图)

然后保存 

到此 wsdl文件已经生成

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

访问路径  http://webserver.com/testwsdl.wsdl  (会出现下面内容)

如果不出现 则要配置apache 使其支持xml

注: 不要用chrome 打开wsdl文件 ,可能会显示不正常 (可以用ie firfox

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 


测试是否可以成功调用

测试工具

wsCaller.jar

注:必需安装JDK 才能运行wsCaller.jar  请不要解压wsCaller.jar

 

如果不能正确返回信息 可直接访问你的php 看看会不会报错

(本例http://webserver.com/rpcservice.php

 

Php 要支持 soap

如果php 版本是5.X 编辑 php.ini

extension=php_soap.dll  (添加 如果存在则去掉注释)

重启一下apache

apache 要注意这个文件 mime.types

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial 

 

函数添加新参数

找到message name=”函数名  中直接复制一下并把参数改一下参数名

WSDL文件

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

Php接口文件

1 function add($a,$b,$e){
2     $c=$a+$b+$e;
3     return $c;
4 }

注:$e 就是wsdl文件中的 c 参数  

添加新的函数

WSDL复制代码就行; PHP写出对应的函数 (看一下选中的部分 其实就是复制了一下add 这个函数 并且直接粘贴在它下面就可以)  下面以 添加add_bak 函数为例

WSDL

1.复制message 标签

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

2.复制 portType 中的标签

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

 

3.Copybinding Tag content

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial
PHP

Copy code The code is as follows:

function add_bak($a,$b,$e){
$c=$a+$b-$e;
return $c;
}


Test results

add_bak function

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

add function

php5 apache 2.2 webservice creation and configuration (java)_PHP tutorial

Other functions have not been tested one by one and screenshots
If there is something wrong, please point it out. Thank you

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322781.htmlTechArticlephp 5 apache 2.2 webservice creation and configuration test tool: wsCaller.jar (this article is for webservice called by java program ) Tip: To run wsCaller.jar, you must choose to install jdk. If it is not installed...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template