zoukankan      html  css  js  c++  java
  • SOAP简单例子

    简介:这是SOAP简单例子的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

    class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339598' scrolling='no'>

    soap_client.php

    <?php
      $client = new SoapClient('http://www.phptest.com/soap/soap_server.php?WSDL');
      //$client = new SoapClient('http://localhost/php/soap/math.wsdl');
      try {
        $result = $client->div(10, 2); // will cause a Soap Fault if divide by zero
        print "The answer is: $result";
      } catch(SoapFault $e) {
        print "Sorry an error was caught executing your request: {$e->getMessage()}";
      }
    
    ?>

    soap_server.php

    <?php
    
    class math {
    
      public function add($a, $b) {
        return $a + $b;
      }
      
      public function div($a, $b) {
        if($b == 0) {
          throw new SoapFault(-1, "Cannot divide by zero!");
        }
        return $a / $b;
      }  
    }
    $server = new SoapServer('math.wsdl', array('soap_version' => SOAP_1_2));
    $server->setClass("math");
    $server->handle();
      
    ?>

    math.wsdl (可以通过zend studio生成)

    <?xml version='1.0' encoding='UTF-8'?>
    
    <!-- WSDL file generated by Zend Studio. -->
    
    <definitions name="math" targetNamespace="urn:math" xmlns:typens="urn:math" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
    	<message name="add">
    		<part name="a" type="xsd:integer"/>
    		<part name="b" type="xsd:integer"/>
    	</message>
    	<message name="addResponse">
    		<part name="addReturn" type="xsd:integer"/>
    	</message>
    	<message name="div">
    		<part name="a" type="xsd:integer"/>
    		<part name="b" type="xsd:integer"/>
    	</message>
    	<message name="divResponse">
    		<part name="divReturn" type="xsd:double"/>
    	</message>
    	<portType name="mathPortType">
    		<documentation>
    			A simple math utility class
    		</documentation>
    		<operation name="add">
    			<documentation>
    				Add two integers together
    			</documentation>
    			<input message="typens:add"/>
    			<output message="typens:addResponse"/>
    		</operation>
    		<operation name="div">
    			<documentation>
    				Div two integers from each other
    			</documentation>
    			<input message="typens:div"/>
    			<output message="typens:divResponse"/>
    		</operation>
    	</portType>
    	<binding name="mathBinding" type="typens:mathPortType">
    		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    		<operation name="add">
    			<soap:operation soapAction="urn:mathAction"/>
    			<input>
    				<soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    			</input>
    			<output>
    				<soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    			</output>
    		</operation>
    		<operation name="div">
    			<soap:operation soapAction="urn:mathAction"/>
    			<input>
    				<soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    			</input>
    			<output>
    				<soap:body namespace="urn:math" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    			</output>
    		</operation>
    	</binding>
    	<service name="mathService">
    		<port name="mathPort" binding="typens:mathBinding">
    			<soap:address location="http://www.phptest.com/soap/soap_server.php"/>
    		</port>
    	</service>
    </definitions>

    爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

    http://biancheng.dnbcw.info/php/339598.html pageNo:7
  • 相关阅读:
    BZOJ-4010 菜肴制作 贪心+堆+(拓扑图拓扑序)
    BZOJ-3670 动物园 KMP+奇怪的东西
    3172
    BZOJ-3668 起床困难综合症 位运算+贪心
    BZOJ-2257 瓶子和燃料 分解因数+数论方面乱搞(裴蜀定理)
    BZOJ-1013 球形空间产生器sphere 高斯消元+数论推公式
    BZOJ-2186 沙拉公主的困惑 线性筛(筛筛筛)+线性推逆元
    BZOJ-2326 数学作业 矩阵乘法快速幂+快速乘
    BZOJ-1705 Longge的问题 一维GCD SUM 乱搞+质因数分解+...
    BZOJ-2875 随机数生成器 矩阵乘法快速幂+快速乘
  • 原文地址:https://www.cnblogs.com/ooooo/p/2245280.html
Copyright © 2011-2022 走看看