利用SOAP扩展开发WebService(PHP)

468 篇文章 0 订阅
346 篇文章 0 订阅

利用SOAP扩展开发WebService(PHP)

标签: webservicesoapphp扩展zendserver
3538人阅读 评论(0) 收藏 举报
本文章已收录于:
分类:

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
 
 

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

    http://blog.csdn.net

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值