php soap 实例

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.youkuaiyun.com/mayongzhan - 马永占,myz,mayongzhan

Server端+Client端+WSDL

声明:很简单!!!!!!

参考了如下:

http://blog.youkuaiyun.com/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.youkuaiyun.com/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.youkuaiyun.com/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.youkuaiyun.com/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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值