PHPsoapWebService uses SoapDiscovery. class. php to generate the wsdl file-zakun

Source: Internet
Author: User
Tags echo date
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 ===============================

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.