client.php
<?php
$a=new SoapClient("http://www.163.com/webserver/TestSoap.wsdl");
echo $a->HelloWorld();
echo("<br />");
echo $a->addcon(80,80);
?>
myservice.php
<?php
class service
{
public function HelloWorld()
{
return "Helldo";
}
public function addcon($a,$b)
{
return $a+$b;
}
}
//TestSoap.wsd需要在后面采用Zend Studio生成。
$server=new SoapServer('TestSoap.wsdl');
$server->setClass("service");
$server->handle();
?>
testsoap.wsdl
<?xml version='1.0' encoding='UTF-8'?>
<!-- WSDL file generated by Zend Studio. -->
<definitions name="TestSoap" targetNamespace="urn:TestSoap" xmlns:typens="urn:TestSoap" 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="addcon">
<part name="a"/>
<part name="b"/>
</message>
<message name="addconResponse">
<part name="addconReturn"/>
</message>
<message name="HelloWorld"/>
<message name="HelloWorldResponse">
<part name="HelloWorldReturn"/>
</message>
<portType name="servicePortType">
<operation name="addcon">
<input message="typens:addcon"/>
<output message="typens:addconResponse"/>
</operation>
<operation name="HelloWorld">
<input message="typens:HelloWorld"/>
<output message="typens:HelloWorldResponse"/>
</operation>
</portType>
<binding name="serviceBinding" type="typens:servicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="addcon">
<soap:operation soapAction="urn:serviceAction"/>
<input>
<soap:body namespace="urn:TestSoap" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:TestSoap" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="HelloWorld">
<soap:operation soapAction="urn:serviceAction"/>
<input>
<soap:body namespace="urn:TestSoap" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:TestSoap" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="TestSoapService">
<port name="servicePort" binding="typens:serviceBinding">
<soap:address location="http://www.163.com/webserver/myservice.php"/>
</port>
</service>
</definitions>
php.ini配置
打开extension=php_soap.dll
[soap]
; Enables or disables WSDL caching feature.
soap.wsdl_cache_enabled=1
; Sets the directory name where SOAP extension will put cache files.
soap.wsdl_cache_dir="/tmp"
; (time to live) Sets the number of second while cached file will be used
; instead of original one.
soap.wsdl_cache_ttl=86400