加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

利用SOAP扩展开发WebService(PHP)

发布时间:2020-12-16 22:04:21 所属栏目:安全 来源:网络整理
导读:利用SOAP扩展开发WebService(PHP) 标签: webservicesoapphp扩展zendserver 2010-09-08 13:26 3538人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: php (9) 作者同类文章 X 版权声明:本文为博主原创文章,未经博主允许不得转载。 PHP 实现 WebService

利用SOAP扩展开发WebService(PHP)

标签: webservicesoapphp扩展zendserver
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
    ?
    ?

    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
      • ?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

      (编辑:李大同)

      【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

        推荐文章
          热点阅读