利用SOAP扩展开发WebService(PHP)
标签: webservicesoapphp扩展zendserver 2010-09-08 13:26 3538人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: 作者同类文章 X版权声明:本文为博主原创文章,未经博主允许不得转载。
PHP实现WebService,它作为一种扩展存在于PHP中。php官方的SOAP扩展,优势是用c开发,相比nusoap效率上较优。
1.在默认情况下,这个扩展是没有被开启的。打开 php.ini文件,找到;extension=php_soap.dll这行,去掉注释符“;”,保存并重启 Apache 服务。
SoapServer类和SoapClient类有两种操作模式:WSDL模式和non-WSDL模式。
在WSDL模式中,构造器可以使用WSDL文件名作为参数,并从WSDL中提取服务所使用的信息。non-WSDL模式中使用参数来传递要使用的信息。
2.服务端soapService.php:
<?php
/*
wsdl方式提供WebService
$server = new SoapServer('Calculator.wsdl');
*/
//non-wsdl方式提供WebService(指定相应的uri)
$server=newSoapServer(null,array("uri"=>"soapService.php"));
$server-> setClass("Calculator");
$server-> handle();
ClassCalculator
{
/**
* Add the two figures together
* @param $num1
* @param $num2
*/
functionaddition($num1,$num2) {
$result=$num1+$num2;
return"{$num1}加{$num2},结果为 ".$result."!";
}
}
?>
然后利用Zend Studio将此php类文件生成WSDL文件。(发现zend studio 7.x版没有这个功能,又不想手动去写,盛怒之下把它给卸载了,装上了6.1.2版。)
3.客户端soapClient.php:
<?php
try{
/*
wsdl方式调用WebService(函数改动后须重新生成wsdl)
$soap = new SoapClient("http://localhost/WebService/Calculator.wsdl");
*/
//non-wsdl方式调用WebService
$soap=newSoapClient(null,array(
'location'=>"http://localhost/WebService/soapService.php",
'uri'=>'soapService.php') );
//两种方式调用函数
$result1=$soap->addition (200,160);
$result2=$soap->__soapCall ("addition",array(50,70) );
echo$result1."<br/>".$result2;
}
catch( SoapFault$e) {echo$e->getMessage (); }
catch( Exception$e) {echo$e->getMessage (); }
?>
- 顶
- 0
- 踩
- 0
- 上一篇利用NuSoap开发WebService(PHP)
- 下一篇配置远程连接SQL Server2005
Eclipse for PHP Developers
Package Description
Tools for PHP developers creating Web applications, including PHP Development Tools (PDT), Web Tools Platform, Mylyn and others.
This package includes:
Detailed features list
- org.eclipse.cvs
- org.eclipse.equinox.p2.user.ui
- org.eclipse.help
- org.eclipse.platform
- org.eclipse.rcp
- org.eclipse.mylyn.ide_feature
- org.eclipse.mylyn.bugzilla_feature
- org.eclipse.mylyn.context_feature
- org.eclipse.mylyn_feature
- org.eclipse.mylyn.wikitext_feature
- org.eclipse.php.sdk
- org.eclipse.wst.jsdt.feature
- org.eclipse.wst.xml_ui.feature
- org.eclipse.wst.web_ui.feature
- org.eclipse.wst.xsl.feature
- org.eclipse.dltk.rse
- org.eclipse.epp.package.common.feature
Maintained by: Eclipse PHP Tools Project
Download Links
Windows 32-bit
Windows 64-bit
Mac OS X (Cocoa) 32-bit
Mac OS X (Cocoa) 64-bit
Linux 32-bit
Linux 64-bit
Downloaded 250 Times
Checksums...
http://blog.csdn.net
- •PHP简单分页类2013-02-01
- •在IIS搭建基于CodeIgniter的PHP网站2010-10-08
- •PHP连接MySQL2010-09-07
- •UTF-8 BOM导致验证码不显示2010-09-07
- •PHP上传图片并生成缩略图_12010-09-07
- •PHP导出CSV2013-02-01
- •利用NuSoap开发WebService(PHP)2010-09-08
- •PHP中/英文验证码2010-09-07
- •PHP上传图片并生成缩略图_22010-09-07