【www.bbyears.com--WebService】
代码如下
代码如下class 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 = "\n";
$headerWSDL.= "
$headerWSDL.= "
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 = "
$serviceWSDL = "
$messageWSDL = "";
foreach ($methods as $method) {
if ($method->isPublic() && !$method->isConstructor()) {
$portTypeWSDL.= "
$bindingWSDL.= "
$messageWSDL.= "
$parameters = $method->getParameters();
foreach ($parameters as $parameter) {
$messageWSDL.= "
}
$messageWSDL.= "
$messageWSDL.= "
$messageWSDL.= "
$messageWSDL.= "
}
}
$portTypeWSDL.= "
$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
}
}
使用方法
代码如下 $a = new SoapDiscovery();然后里面的方法与类就可以直接调用了哦。