Summary of PHP generated WSDL file method

Source: Internet
Author: User
Tags foreach soap php file xmlns wsdl

In Zend Studio9, unlike previous versions, you need to install the WSDL plug-in separately before you can use the following steps:

1. Open zendstudio9 and choose Help (->welcome) (Welcome

2, in the list on the right to find the WSDL Support, check

3, click Apply Changes (apply to modify)

4, Zde will automatically install, and then prompted to reboot, click Restart Now (reboot)

WSDL support installation complete, let's generate a WSDL file, as follows:

1. Select the project folder where the WSDL is saved

2, right key-new (new)->other (other)

3. Select Web Services in the pop-up dialog box, select WSDL file in the Subordinate menu, click Next to enter the next step

4, name your WSDL file, click Next to enter the next step

5, modify target namespace (target namespace), the other unchanged, click Finish.

A WSDL file is generated, as shown in the following illustration:

Testsoapsoap below fill in PHP webService such as soapservice.php

Click the right mouse button on the newoperation:
Newoperation: Add a method. WebService a method name that needs to be supplied to someone else
Input: Setting enter parameter names and types
Output: Sets the return value.
Add part: If added in input, is to add multiple parameters
Set Type/set element: The Input/output type of the set parameter contains common data types (Int,string,boolean,float,time ...), and element is the custom element type.

. using SoapDiscovery.class.php to generate

The code is as follows Copy Code
<?php
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 = "<?xml version=" 1.0 ">n";
$headerWSDL. = "<definitions name=" $this->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. = "<types xmlns=" http://schemas.xmlsoap.org/wsdl/"/>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 = ' <porttype name= '. $this->service_name. ' Port ' > ';
$bindingWSDL = ' <binding name= '. $this->service_name. ' Binding ' type= ' TNS: '. $this->service_name. " Port ">n<soap:binding style=" rpc "transport=" http://schemas.xmlsoap.org/soap/http "/>n";
$serviceWSDL = ' <service name= '. $this->service_name. " >n<documentation/>n<port name= "". $this->service_name. ' Port ' binding= ' TNS: '. $this->service_name ." Binding "><soap:address location=" http://"$_server[' server_name '". '. $_server[' server_port '].$_SERVER[' Php_self ']. "/>n</port>n</service>n";
$messageWSDL = ';
foreach ($methods as $method) {
if ($method->ispublic () &&! $method->isconstructor ()) {
$portTypeWSDL. = ' <operation name= '. $method->getname (). "" >n "." <input message= "TNS: '. $method->getname ()." Request "/>n<output message=" TNS: ". $method->getname ()." Response "/>n</operation>n";
$bindingWSDL. = ' <operation name= '. $method->getname (). "" >n "." <soap:operation soapaction= "urn: '. $this->service_name." # '. $this->class_name. ' # '. $method->getname (). "" "/>n<input><soap:body use=" encoded "namespace=" urn: $this->service_name " Encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/"/>n</input>n<output>n<soap:body use= "Encoded" namespace= "urn: $this->service_name" encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/"/>n </output>n</operation>n ";
$messageWSDL. = ' <message name= '. $method->getname (). " Request ">n";
$parameters = $method->getparameters ();
foreach ($parameters as $parameter) {
$messageWSDL. = ' <part name= '. $parameter->getname (). "Type=" xsd:string "/>n";
}
$messageWSDL. = "</message>n";
$messageWSDL. = ' <message name= '. $method->getname (). " Response ">n";
$messageWSDL. = ' <part name= '. $method->getname (). "Type=" xsd:string "/>n";
$messageWSDL. = "</message>n";
}
}
$portTypeWSDL. = "</porttype>n";
$bindingWSDL. = "</binding>n";
return sprintf ('%s%s%s%s%s%s ', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, ' </ Definitions> ');
}

/**
* Soapdiscovery::getdiscovery () Returns discovery of WSDL.
*
* @return String
**/
Public Function Getdiscovery () {
Return "<?xml version=" 1.0 ">n<disco:discovery xmlns:disco=" http://schemas.xmlsoap.org/disco/"xmlns:scl= "http://schemas.xmlsoap.org/disco/scl/" >n<scl:contractref ref= "http://" $_server[' server_name '. '. $_ server[' server_port '].$_server[' php_self '. " WSDL "/>n</disco:discovery>";
}
}

?>

Use case:

The code is as follows Copy Code

<?php
Include ("compute.php"); The file you want to generate
Include ("SoapDiscovery.class.php");

$disco = new Soapdiscovery (' Compute ', ' Compute ');//The first argument is the class name (the generated WSDL file is named for it), the person class, and the second parameter is the name of the service (this can be written casually).
$WSDL = $disco->getwsdl ();
$disco->getdiscovery ();
$fp = fopen ("compute.wsdl", "w");
Fwrite ($fp, $wsdl);
?>


Method Two of the most important is our SoapDiscovery.class.php file, the file on the Internet has downloaded everyone can find Baidu.

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.