php soap 執行個體

來源:互聯網
上載者:User

著作權聲明:原創作品,允許轉載,轉載時請務必以超連結形式標明文章原始出版、作者資訊和本聲明。否則將追究法律責任。http://blog.csdn.net/mayongzhan - 馬永占,myz,mayongzhan

Server端+Client端+WSDL

聲明:很簡單!!!!!!

參考了如下:

http://blog.csdn.net/phphot/archive/2007/07/15/1692109.aspx

先建Server,然後使用wsdl工具來產生wsdl,我用的是zend development environment,

在zde中的tools中的wsdl generator wizard

第一頁是名字,和輸出地址(輸出後直接挪過去就OK)

第二頁是類和地址,類挑上勾,URL那裡添server那個檔案的地址

第三頁 finish

別忘了拷那個wsdl過去...

記得server引用的那個類檔案裡不要有輸出.

一共有兩個需要添地址的地方

一個是wsdl中的描述http://127.0.0.1/test/CulculatorServer.php

一個是client中的串連http://127.0.0.1/test/Culculator.wsd

類檔案

<?php

/**

 * @name Culculator.php

 * @date Fri Jan 25 12:43:40 CST 2008

 * @copyright 馬永占(MyZ)

 * @author 馬永占(MyZ)

 * @link http://blog.csdn.net/mayongzhan/

 */

 

class Culculator

{

       /**

        * 求和

        *

        * @param float $x

        * @param float $y

        * @return float

        */

       public function add($x, $y)

       {

              return $x + $y;

       }

}

?>

 

Server

 

<?php

/**

 * @name CulculatorServer.php

 * @date Fri Jan 25 12:44:04 CST 2008

 * @copyright 馬永占(MyZ)

 * @author 馬永占(MyZ)

 * @link http://blog.csdn.net/mayongzhan/

 */

 

include('./Culculator.php');

$server = new SoapServer('./Culculator.wsdl');

$server->setClass('Culculator');

$server->handle();

?>

 

Client

 

<?php

/**

 * @name CulculatorClient.php

 * @date Fri Jan 25 12:43:54 CST 2008

 * @copyright 馬永占(MyZ)

 * @author 馬永占(MyZ)

 * @link http://blog.csdn.net/mayongzhan/

 */

 

$soap = new SoapClient('http://127.0.0.1/test/Culculator.wsdl');

echo $soap->add(1, 2);

?>

 

WSDL

 

<?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="x" type="xsd:float"/>

              <part name="y" type="xsd:float"/>

       </message>

       <message name="addResponse">

              <part name="addReturn" type="xsd:float"/>

       </message>

       <portType name="CulculatorPortType">

              <operation name="add">

                     <documentation>

                            求和

                     </documentation>

                     <input message="typens:add"/>

                     <output message="typens:addResponse"/>

              </operation>

       </portType>

       <binding name="CulculatorBinding" type="typens:CulculatorPortType">

              <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

              <operation name="add">

                     <soap:operation soapAction="urn:CulculatorAction"/>

                     <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="CulculatorPort" binding="typens:CulculatorBinding">

                     <soap:address location="http://127.0.0.1/test/CulculatorServer.php"/>

              </port>

       </service>

</definitions>

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.