* RPC Style -- 表明http body为soap format o The RPC style specifies that the <soap:body> contains an element with the name of the Web method being invoked. This element in turn contains an entry for each parameter and the return value of this method. * Document Style -- 需要server端程序解析http body o The message parts appear directly under the <soap:body> element. There are no SOAP formatting rules for what the <soap:body> contains. The server application is responsible for mapping the server objects (parameters, method calls, and so forth) and the values of the XML documents.所以 <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 应改为 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
=====================================================
<?php
$soapClient = new SoapClient("http://localhost/soap/hello.wsdl",array("login"=>"admin","password"=>"123456"));echo $soapClient->hw('hello','world');?>
soapserver.php
=========================================
<?php
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
!($_SERVER['PHP_AUTH_USER']=='admin' && $_SERVER['PHP_AUTH_PW']=='123456')) {
header('WWW-Authenticate: Basic realm="WEBSERVICE"');
header("HTTP/1.0 401 Unauthorized");
echo "You must enter a valid login ID and password to access this resource\n";
die;
}
class serverClass
{
function hw($name,$pass)
{
return $name." ".$pass;
}
}
$soapServer = new SoapServer("hello.wsdl");
$soapServer->setClass('serverClass');
$soapServer->handle();
?>hello.wsdl
wsdl的详细文档配置信息去w3cschool研究下。
==============================================
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='lake' targetNamespace='http://localhost/soap/' xmlns:tns='http://localhost/soap/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'><message name='getRequest'>
<part name='name' type='xsd:string'/>
<part name='pass' type='xsd:string'/>
</message><message name='getResponse'> <part name='Result' type='xsd:string'/>
</message><portType name='class'>
<operation name='hw'>
<input message='tns:getRequest'/>
<output message='tns:getResponse'></output>
</operation>
</portType><binding name='class' type='tns:class'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='hw'>
<soap:operation soapAction=''/>
<input>
<soap:body namespace="xmlns:tns" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="xmlns:tns" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding><service name='class'>
<port name='goforsoap' binding='class'>
<soap:address location='http://localhost/soap/soapserver.php'/>
</port>
</service>
</definitions>
用zend 吗?
<message name="hw">
<part name="name"/>
<part name="pass"/>
</message>
<message name="hwResponse">
<part name="hwReturn"/>
</message>
<portType name="serverClassPortType">
<operation name="hw">
<input message="typens:hw"/>
<output message="typens:hwResponse"/>
</operation>
</portType>
<binding name="serverClassBinding" type="typens:serverClassPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hw">
<soap:operation soapAction="urn:serverClassAction"/>
<input>
<soap:body namespace="urn:b1" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:b1" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="b1Service">
<port name="serverClassPort" binding="typens:serverClassBinding">
<soap:address location="http://localhost/soap/soapserver.php"/>
</port>
</service>
</definitions>
o The RPC style specifies that the <soap:body> contains an element with the name of the Web method being invoked. This element in turn contains an entry for each parameter and the return value of this method. * Document Style -- 需要server端程序解析http body
o The message parts appear directly under the <soap:body> element. There are no SOAP formatting rules for what the <soap:body> contains. The server application is responsible for mapping the server objects (parameters, method calls, and so forth) and the values of the XML documents.所以
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
应改为
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>