step1:修改php.ini

extension=php_soap.dll

step2:服务器端代码
soapserver.php

class service
{private $username = "";private $password = "";function __construct() { $xml = file_get_contents('php://input');$p = xml_parser_create();xml_parse_into_struct($p, $xml, $vals, $index);xml_parser_free($p);$this->username = $vals[5]['value'];$this->password = $vals[9]['value'];$logs .= date("Y-m-d H:i:s")."\r\n";$logs.=$xml.="\r\n";$logs .= "username:".$this->username."\r\n" ;$logs .= "password:".$this->password."\r\n";//写日志 $path = "./log".date("YmdH").".txt";if(!is_writable($path)){@touch($path);}$fp = @fopen($path,'a');if($fp){@fwrite($fp,$logs);}$this->isLogin();}public function isLogin(){if($this->username != '1' || $this->password != md5('1')){throw new SoapFault('1001', '您无权访问');}}public  function Add($a,$b){return $a+$b;}public  function Sub($a,$b){return $a-$b;}public function Say($name){return " Hello ".$name;}}
$server=new SoapServer('http://localhost/test/soap/soap.wsdl',array('soap_version' => SOAP_1_2,'actor' => 'laruence'));
$server->setClass("service");
$server->handle();

 

3、客户端代码

client.php

$soap      = new SoapClient('http://localhost/test/soap/soap.wsdl',array("trace"=>true));
$header    = new SoapHeader('http://localhost/test/soap/', 'auth', array("username"=>"1","password"=>md5("1")), false, SOAP_ACTOR_NEXT);$soap->__setSoapHeaders(array($header));
try {echo $pack = $soap->Say("123");echo "\r\n";echo $pack = $soap->Add(123,456);
} catch (Exception $e) {echo $soap->__getLastRequest();  echo $soap->__getLastResponse(); echo $e->getMessage();
}

4、WSDL文件,可以用zend Studio 生成

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/test/soap/soapserver.php"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"name="soap" targetNamespace="http://localhost/test/soap/"><!-- 定义数据类型 --><wsdl:types><xsd:schema targetNamespace="http://localhost/test/soap/"><xsd:element name="Add"><xsd:complexType><xsd:sequence><xsd:element name="in" type="xsd:int" /></xsd:sequence></xsd:complexType></xsd:element><xsd:element name="AddResponse"><xsd:complexType><xsd:sequence><xsd:element name="out" type="xsd:int" /></xsd:sequence></xsd:complexType></xsd:element>             </xsd:schema><xsd:schema targetNamespace="http://localhost/test/soap/"><xsd:element name="Sub"><xsd:complexType><xsd:sequence><xsd:element name="in" type="xsd:int" /></xsd:sequence></xsd:complexType></xsd:element><xsd:element name="SubResponse"><xsd:complexType><xsd:sequence><xsd:element name="out" type="xsd:int" /></xsd:sequence></xsd:complexType></xsd:element>             </xsd:schema><xsd:schema targetNamespace="http://localhost/test/soap/"><xsd:element name="Say"><xsd:complexType><xsd:sequence><xsd:element name="in" type="xsd:sting" /></xsd:sequence></xsd:complexType></xsd:element><xsd:element name="SayResponse"><xsd:complexType><xsd:sequence><xsd:element name="out" type="xsd:string" /></xsd:sequence></xsd:complexType></xsd:element>             </xsd:schema></wsdl:types><!-- 参数 --><wsdl:message name="AddRequest">        <wsdl:part name="a" type="xsd:int"></wsdl:part><wsdl:part name="b" type="xsd:int"></wsdl:part></wsdl:message><wsdl:message name="AddResponse"><wsdl:part name="c" type="xsd:int"></wsdl:part></wsdl:message><wsdl:message name="SubRequest">        <wsdl:part name="d" type="xsd:int"></wsdl:part><wsdl:part name="e" type="xsd:int"></wsdl:part></wsdl:message><wsdl:message name="SubResponse"><wsdl:part name="f" type="xsd:int"></wsdl:part></wsdl:message><wsdl:message name="SayRequest">        <wsdl:part name="g" type="xsd:string"></wsdl:part>      </wsdl:message><wsdl:message name="SayResponse"><wsdl:part name="h" type="xsd:string"></wsdl:part></wsdl:message><!-- 方法 --><wsdl:portType name="soap"><wsdl:operation name="Add"><wsdl:input message="tns:AddRequest" /><wsdl:output message="tns:AddResponse" /></wsdl:operation><wsdl:operation name="Sub"><wsdl:input message="tns:SubRequest" /><wsdl:output message="tns:SubResponse" /></wsdl:operation><wsdl:operation name="Say"><wsdl:input message="tns:SayRequest" /><wsdl:output message="tns:SayResponse" /></wsdl:operation></wsdl:portType><wsdl:binding name="soapSOAP" type="tns:soap"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="Add"><soap:operation soapAction="http://localhost/test/soap/Add"/><wsdl:input><soap:body use="literal" namespace="http://localhost/test/soap/" /></wsdl:input><wsdl:output><soap:body use="literal" namespace="http://localhost/test/soap/" /></wsdl:output></wsdl:operation><wsdl:operation name="Sub"><soap:operation soapAction="http://localhost/test/soap/Sub"/><wsdl:input><soap:body use="literal" namespace="http://localhost/test/soap/" /></wsdl:input><wsdl:output><soap:body use="literal" namespace="http://localhost/test/soap/" /></wsdl:output></wsdl:operation><wsdl:operation name="Say"><soap:operation soapAction="http://localhost/test/soap/Sub"/><wsdl:input><soap:body use="literal" namespace="http://localhost/test/soap/" /></wsdl:input><wsdl:output><soap:body use="literal" namespace="http://localhost/test/soap/" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="soap"><wsdl:port binding="tns:soapSOAP" name="soapSOAP"><soap:address location="http://localhost/test/soap/soapserver.php" /></wsdl:port></wsdl:service>
</wsdl:definitions>

转载于:https://www.cnblogs.com/lsl8966/archive/2012/11/28/2793334.html

php soap webservice 实例相关推荐

  1. android网络通信之SOAP教程实例汇总

    一.实例教程:Android网络通信之 SOAP教程篇: 1.android webservice通信之ksoap http://www.eoeandroid.com/thread-162563-1- ...

  2. delphi2010 开发及调试WebService 实例

    delphi2010 开发及调试WebService 实例 基于Delphi的WebService编写 Delphi编写soap服务器与客户端程序 Delphi XE5通过WebService开发We ...

  3. java webservice接口开发_搭建Soap webservice api接口测试案例系统

    Eclipse下创建WebService项目,主要目的是作为Postman.soapUI等工具进行soap webservice 接口测试的案例. 本文基于Axis2框架,在eclipse环境下搭建w ...

  4. soapui自带的webservice实例 MockService

    soapui自带的webservice实例 & MockService: http://www.docin.com/p-646423228.html 转载于:https://www.cnblo ...

  5. CXF发布RestFul WebService和SOAP WebService

    CXF发布RestFul WebService和SOAP WebService Apache CXF可以发布多种协议的WebService,Spring支持整合cxf到项目中,可以简化后台构架,以下是 ...

  6. spring boot 开发soap webservice

    介绍 spring boot web模块提供了RestController实现restful,第一次看到这个名字的时候以为还有SoapController,很可惜没有,对于soap webservic ...

  7. java webservice测试_搭建Soap webservice api接口测试案例系统

    Eclipse下创建WebService项目,主要目的是作为Postman.soapUI等工具进行soap webservice 接口测试的案例. 本文基于Axis2框架,在eclipse环境下搭建w ...

  8. Java 使用Axis实现WebService实例

    在上一篇WebService实例中,基于jdk1.6以上的javax.jws 发布webservice接口.这篇博文则主要用eclipse/myeclipse 使用axis插件进行发布和调用WebSe ...

  9. java .net webservice_Java客户端调用.NET的WebService实例

    项目需要去调用.NET的WebSrevice,本身是Java,研究了半天,终于有些头绪,记下来. 1,新建.NET WebService.只在原方法上加上一个string类型的参数str [WebMe ...

最新文章

  1. struts2提交list
  2. 线程关键字、锁、同步集合笔记
  3. C++_STL——list(and forward_list)
  4. php 数组移除指定健,php删除数组指定键的方法
  5. 观察者模式Java实现
  6. 搞了多年管理软件,总算说清楚了什么是好软件
  7. 《Go 语言程序设计》读书笔记(十)反射
  8. 为什么我不推荐敏捷开发?
  9. practical of programming 第二章 java的quick sort
  10. VB 创建快捷方式函数(可带参数)
  11. 链路层发现协议LLDP
  12. selenium报错 : WebDriverException: ‘chromedriver‘ executable needs to be in PATH解决方案
  13. appium+python环境搭建_想学习自动化测试,已经学习了appium+python环境搭建和python的简单内容,下面该怎么做?...
  14. 计算机网络第七版1-1
  15. tcl语言读取文件一行_TCL语言(九) 路径和文件
  16. UWP 如何阻止WebView自动打开浏览器?
  17. 无法将数据库从SINGLE_USER模式切换回MULTI_USER模式(Error 5064)
  18. c语言程序设计精髓第五章编程题
  19. 海瑞菌的web前端学习直播间
  20. Elasticsearch关闭index的自动日期检测

热门文章

  1. Typescript-规范
  2. 咨询公司建议完美批准私有化
  3. 医院管理系统的新机遇
  4. 云爆发架构是否难以实施?
  5. mysql 编译安装
  6. ReentrantLock可重入锁的使用场景(转)
  7. zabbix之通过jmx监控tomcat
  8. Delphi 复习代码
  9. 在内部循环中Continue外部循环
  10. 金融科技创业公司Revolut增加对BCH和XRP支持