Recently, I started to prepare phpwebservice programming. how can I generate a wsdl file? there are two methods: 1. zendstudio generation directly seems to be generated for versions earlier than zendstudio9:
Recently, I started to program php webservice, which involves the wsdl file. There are two ways to generate this:
1. zend studio generation
Zend studio 9 and earlier versions seem to be directly generated:
File-> New-> Other-> Webservice-> WSDL
For zend studio 9, you need to install the wsdl plug-in:
1. open zendstudio9 and select help> welcome.
2. find the WSDL Support in the list on the right, and select
3. click Apply changes)
4. zde will be automatically installed, and then prompt to restart, click restart now (restart now)
After the installation is complete, we generate a wsdl file. The steps are as follows:
1. select the project folder for saving the wsdl
2. right-click-new (new)-> other (others)
3. in the pop-up dialog box, select web services, select WSDL file from the lower menu, and click next to go to the next step.
4. name your wsdl file and click next to go to the next step.
5. modify the target namespace (the target namespace), and click finish.
2. use SoapDiscovery. class. php to generate
Source code of this file:
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, '
');}/** * SoapDiscovery::getDiscovery() Returns discovery of WSDL. * * @return string **/public function getDiscovery() {return "
\n
\n
\n
";}}?>
Use case:
GetWSDL (); // $ disco-> getDiscovery (); $ fp = fopen ("Compute. wsdl "," w "); fwrite ($ fp, $ wsdl);?>