Create a new project first
Create the following files in the project
PHP class file test.php
<?PHPclassTest { Public function__construct () {} Public functionAdd$name,$age) { $result=Array(' REV ' =false); $result[' REV '] =true; $result[' DATA '] = 1; $result= Json_encode ($result); return $result; } Public functionDel$id) { $result=false; return $result; } Public functionGetList$type) { $result=Array( Array(' name ' = ' Zhang San ', ' age ' =>18),Array(' name ' = ' John Doe ', ' age ' =>20),Array(' name ' = ' JMS ', ' age ' =>10),Array(' name ' = ' jk Chen ', ' age ' =>8), ); $result= Json_encode ($result); return $result; }}?>
Generating a WSDL file using Zendstudio
The resulting file format is as follows
<?XML version= "1.0" encoding= "UTF-8" standalone= "no"?><wsdl:definitionsXmlns:soap= "http://schemas.xmlsoap.org/wsdl/soap/"Xmlns:tns= "Http://localhost/t/ws"xmlns:wsdl= "http://schemas.xmlsoap.org/wsdl/"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"name= "Test_server"targetnamespace= "Http://localhost/t/ws"> <Wsdl:types> <Xsd:schematargetnamespace= "Http://localhost/t/ws"> <xsd:elementname= "GetList"> <Xsd:complextype> <xsd:sequence> <xsd:elementname= "in"type= "Xsd:string"/> </xsd:sequence> </Xsd:complextype> </xsd:element> <xsd:elementname= "Getlistresponse"> <Xsd:complextype> <xsd:sequence> <xsd:elementname= "Out"type= "Xsd:string"/> </xsd:sequence> </Xsd:complextype> </xsd:element> </Xsd:schema> </Wsdl:types> <Wsdl:messagename= "Getlistrequest"> <Wsdl:partname= "type"type= "Xsd:int"/> </Wsdl:message> <Wsdl:messagename= "Getlistresponse"> <Wsdl:partname= "Resultrespose"type= "Xsd:string"/> </Wsdl:message> <Wsdl:porttypename= "Test_server"> <wsdl:operationname= "GetList"> <Wsdl:inputmessage= "Tns:getlistrequest"/> <Wsdl:outputmessage= "Tns:getlistresponse"/> </wsdl:operation> </Wsdl:porttype> <wsdl:bindingname= "Test_serversoap"type= "Tns:test_server"> <soap:bindingstyle= "Document"Transport= "Http://schemas.xmlsoap.org/soap/http" /> <wsdl:operationname= "GetList"> <soap:operationSOAPAction= "Http://localhost/t/ws/NewOperation" /> <Wsdl:input> <Soap:body Use= "literal" /> </Wsdl:input> <Wsdl:output> <Soap:body Use= "literal" /> </Wsdl:output> </wsdl:operation> </wsdl:binding> <Wsdl:servicename= "Test_server"> <Wsdl:portbinding= "Tns:test_serversoap"name= "Test_serversoap"> <soap:address Location= "http://localhost/t/ws/server.php"/> </Wsdl:port> </Wsdl:service></wsdl:definitions>
Calling the server's file server.php
<? PHP Ini_set ("soap.wsdl_cache_enabled", "0"); // open to prevent soap cache when testing include ("test.php"); $Server=new soapserver (' test_server.wsdl '); // SoapServer $Server->setclass ("Test"); $Server-handle ();? >
Testing a file that calls webserver WSDL
<?PHPIni_set("soap.wsdl_cache_enabled", "0");//$url = ' http://localhost/t/ws/test_server.wsdl ';$url= ' http://localhost/t/ws/server.php?wsdl ';//Two types of URLs are available$client=NewSoapClient ($url);$params=Array(' type ' =>1);$res=$client->__soapcall (' GetList ',Array(' Parameters ' =$params));Var_dump($res);?>
Return Data:
String
Call succeeded
PHP uses Zendstudio to generate WebService file WSDL