首页 > php代码 > php soap 实例

php soap 实例

Server端+Client端+WSDL

 

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

参考了如下:

 

先建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.phprm.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.phprm.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.phprm.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>


本文地址:http://www.phprm.com/code/0bcde19a0914eeb8c8934869ed952945.html

转载随意,但请附上文章地址:-)

标签:none

发表留言