著作權聲明:原創作品,允許轉載,轉載時請務必以超連結形式標明文章原始出版、作者資訊和本聲明。否則將追究法律責任。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>