WSDL
WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问。这种文档可描述某个 Web service。它可规定服务的位置,以及此服务提供的操作(或方法)。
一个 WSDL 文档的主要结构是类似这样的:
definition of types........ definition of a message.... definition of a port....... definition of a binding....
WSDL 文档可包含其它的元素,比如 extension 元素,以及一个 service 元素,此元素可把若干个 web services 的定义组合在一个单一的 WSDL 文档中。
PHP生成WSDL
类代码(SoapDiscovery.class.php):
<?phpclass SoapDiscovery { private $class_name = ''; private $service_name = ''; /** * SoapDiscovery::__construct() SoapDiscovery class Constructor. * * @param string $class_name * @param string $service_name **/ public function __construct($class_name = '', $service_name = '') { $this->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 = "<?xml version="1.0" ?>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:tn<b>本文来源gao@!dai!ma.com搞$$代^@码5网@</b>s="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 = 'service_name.'Port">'; $bindingWSDL = 'service_name.'Binding" type="tns:'.$this->service_name."Port">nn"; $serviceWSDL = 'service_name."">nnservice_name.'Port" binding="tns:'.$this->service_name."Binding">nnn"; $messageWSDL = ''; foreach ($methods as $method) { if ($method->isPublic() && !$method->isConstructor()) { $portTypeWSDL.= 'getName()."">n".'getName()."Request" />ngetName()."Response" />nn"; $bindingWSDL.= 'getName()."">n".'service_name.'#'.$this->class_name.'#'.$method->getName()."" />nservice_name" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />nnnservice_name" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />nnn"; $messageWSDL.= 'getName()."Request">n"; $parameters = $method->getParameters(); foreach ($parameters as $parameter) { $messageWSDL.= 'getName()."" type="xsd:string" />n"; } $messageWSDL.= "n"; $messageWSDL.= 'getName()."Response">n"; $messageWSDL.= 'getName()."" type="xsd:string" />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 "<?xml version="1.0" ?>nnn"; }} ?>