PHP5 - Generating WSDL with Zend Studio 5.1
Translation of the original in Catalan. Read it in: CatalàCastellano
Part 1 of 3SOAP web services with PHP5
- PHP5 - Generating WSDL with Zend Studio 5.1
- PHP5: passing objects as a parameter in a SOAP call
- PHP5: passing and returning objects as a parameter in a SOAP call (Part II)
When programming a webservice with PHP5 it's more than trivial as we can read in PHP's own documentation about SOAP (local). The problem comes when, wanting to take advantage of the simplicity of SOAP services, you have to program the WSDL by hand. That is, go ahead and start defining in XML the interface of the class/es you want to export through the webservice, that is, a mission impossible.
My surprise was to see that after adopting Zend Studio as the programming IDE for my PHP code I saw that it had a wizard that is quite simple to use in order to generate this WSDL file automatically. The thing is quite simple, let's imagine that we use the code from the example on the Zend website, as I was saying before.
The SOAP server:
<?php
class QuoteService {
private $quotes = array("ibm" => 98.42);
function getQuote($symbol) {
if (isset($this->quotes[$symbol])) {
return $this->quotes[$symbol];
} else {
throw new SoapFault("Server","Unknown Symbol '$symbol'.");
}
}
}
$server = new SoapServer("server2.wsdl");
$server->setClass("QuoteService");
$server->handle();
?>
The client, even simpler than the server:
<?php
$client = new SoapClient("server2.wsdl");
print($client->getQuote("ibm"));
?>
Now that we have the code in our Zend, we only have to go to:

You have to follow the wizard, which isn't too difficult, here you have the steps captured for the example we're talking about:


You can see how the classes of the files you select are exported automatically, you have to put next to each exported class the URL through which the service is accessed:

In the end we get the WSDL file, in our case this one:
<?xml version='1.0' encoding='UTF-8'?>
<!-- WSDL file generated by Zend Studio. -->
<definitions name="server2" targetNamespace="urn:server2" xmlns:typens="urn:server2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="getQuote">
<part name="symbol"/>
</message>
<message name="getQuoteResponse">
<part name="getQuoteReturn"/>
</message>
<portType name="QuoteServicePortType">
<operation name="getQuote">
<input message="typens:getQuote"/>
<output message="typens:getQuoteResponse"/>
</operation>
</portType>
<binding name="QuoteServiceBinding" type="typens:QuoteServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getQuote">
<soap:operation soapAction="urn:QuoteServiceAction"/>
<input>
<soap:body namespace="urn:server2" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:server2" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="server2Service">
<port name="QuoteServicePort" binding="typens:QuoteServiceBinding">
<soap:address location="http://oriol.joor.net/soap/server2.php"/>
</port>
</service>
</definitions>
If you're observant you'll notice that this file is slightly different from the one in the documentation Zend shows. But I've tried it and it works perfectly so I won't rack my brains over what these small changes are due to when implementing this XML format.
5 comments
Comments from the old blog, as they were written. Comments are closed.
—
Acabo d'escriure l'article me'n vaig a fer un cop d'ull al bloglines i allà em trobo la notícia de que Zend i IBM, han arribat a un acord perquè Eclipse, la IDE de Java i C++ d'IBM, es posi a treballar per donar suport al PHP com tecnologia integrada dins de la IDE, inicialment el suport serà a través de plug-ins.
Per més informació sobre el tema la notícia d'Eclipse:
Eclipse Foundation, Zend Technologies, and IBM Announce the Approval of the PHP IDE Project
Ernest
Per si algun dia et trobes que vols fer el proces a la inversa
—
[2]
ostres que ben parit, gràcies. Tot i que també s'ha de dir que s'han de tenir quadrats per escriure a pelo un WSDL. O això o acabes com el de la foto de l'article del SOAP :)
Ernest
Aixo es veritat, mes que res es per aprofitar aquells llocs que l'unic que et faciliten es el wsdl pq tu et generis els teus fitxers interficie per utilitzar el servei. Com per exemple la ja antiga api de google
—
[4] bona idea... veus això no se m'havia acudit. Però realment és una part molt útil de l'eina que comentes. Ja ho intentaré tenir en compte.
Per cert, ja m'he instal·lat el Zend Studio 5.1 per Linux. De fet, esta programat en Java i treballa sobre el JRE però dins del que cap va prou bé.