PHPsoapWebService uses SoapDiscovery. class. php to generate the wsdl file-zakun PHP soap web service uses the wsdl file demo:
========================================================== ======================================
Server:
Use the cw. php file to generate the wsdl file before using the soap webservice demo of wsdl. the code is as follows:
Cw. php:
GetWSDL ();
?>
Service. php:
SOAP_1_2); # Service. the wsdl file is the $ server-> setClass ("soapHandle") generated above; // all methods for registering the Service class $ server-> handle (); // process the request?>
SoapHandle. class. php:
The SoapDiscovery. class. php code is as follows:
========================================================== ==============================
class_name = $class_name; $this->service_name = $service_name; } /** * SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable. * * @return string **/ public function getWSDL() { if (empty($this->service_name)) { throw new Exception('No service name.'); } $headerWSDL = "
\n"; $headerWSDL.= "
service_name\" targetNamespace=\"urn:$this->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:$this->service_name\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n"; $headerWSDL.= "
\n"; if (empty($this->class_name)) { throw new Exception('No class name.'); } $class = new ReflectionClass($this->class_name); if (!$class->isInstantiable()) { throw new Exception('Class is not instantiable.'); } $methods = $class->getMethods(); $portTypeWSDL = '
'; $bindingWSDL = '
\n
\n"; $serviceWSDL = '
\n
\n
service_name.'Port" binding="tns:'.$this->service_name."Binding\">
\n
\n
\n"; $messageWSDL = ''; foreach ($methods as $method) { if ($method->isPublic() && !$method->isConstructor()) { $portTypeWSDL.= '
\n".'
\n
getName()."Response\" />\n
\n"; $bindingWSDL.= '
\n".'
\n
service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n\n
\n
service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n
\n
\n"; $messageWSDL.= '
\n"; $parameters = $method->getParameters(); foreach ($parameters as $parameter) { $messageWSDL.= '
\n"; } $messageWSDL.= "
\n"; $messageWSDL.= '
\n"; $messageWSDL.= '
\n"; $messageWSDL.= "
\n"; } } $portTypeWSDL.= "
\n"; $bindingWSDL.= "\n"; //return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '
'); $fso = fopen($this->class_name . ".wsdl", "w"); fwrite($fso, sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '')); } /** * SoapDiscovery::getDiscovery() Returns discovery of WSDL. * * @return string **/ public function getDiscovery() { return "
\n
\n
\n
"; }}?>
View Code
Client:
Client. php code:
========================================================== ==================================
Strtolink ('http: // www.baidu.com ')."
"; Echo $ soap-> add (28,100 )."
"; Echo $ soap->__ soapCall ('Add', array (28,200 ))."
"; // Or Call echo $ soap->__ Call ('Add', array (28,300 ))."
"; Echo date ('Y-m-d H: I: S', time ();?>
====================== END ===============================