|
Tutoriel 1 : Simple Webservice client
Fichier: /pages/tutorials/webservice/helloworld-01-client.php
<?php /* * Use: http://YOUR_DOMAIN/tutorials/webservice/ * helloworld-01-client.html */
class Helloworld01Client extends Page { public function InitializeComponent() { parent::$PAGE_TITLE = "Simple Webservice client"; // Init webservice $client = new WebSitePhpSoapClient( $this->getBaseLanguageURL(). "/tutorials/webservice/". "helloworld-01-server.wsdl?wsdl"); // call web services methods $client->setLogin("Your Login"); $hello = $client->helloWorld(); $welcome = $client->welcomeMessage("red"); $welcome = html_entity_decode($welcome); // display result message $this->render = new WSPObject($hello, "<br/>", $welcome); } } ?>
Tutoriel 2 : Simple Webservice server (WSDL)
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Helloworld01" targetNamespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"><types><xsd:schema targetNamespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></types><portType name="Helloworld01Port"><operation name="setLogin"><documentation>setLogin</documentation><input message="tns:setLoginIn"/><output message="tns:setLoginOut"/></operation><operation name="helloWorld"><documentation>helloWorld</documentation><input message="tns:helloWorldIn"/><output message="tns:helloWorldOut"/></operation><operation name="welcomeMessage"><documentation>welcomeMessage</documentation><input message="tns:welcomeMessageIn"/><output message="tns:welcomeMessageOut"/></operation><operation name="getSessionId"><documentation>Method getSessionId</documentation><input message="tns:getSessionIdIn"/><output message="tns:getSessionIdOut"/></operation></portType><binding name="Helloworld01Binding" type="tns:Helloworld01Port"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="setLogin"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl#setLogin"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></output></operation><operation name="helloWorld"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl#helloWorld"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></output></operation><operation name="welcomeMessage"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl#welcomeMessage"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></output></operation><operation name="getSessionId"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl#getSessionId"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></output></operation></binding><service name="Helloworld01Service"><port name="Helloworld01Port" binding="tns:Helloworld01Binding"><soap:address location="https://www.website-php.com/fr/tutorials/webservice/helloworld-01-server.wsdl"/></port></service><message name="setLoginIn"><part name="login" type="xsd:string"/></message><message name="setLoginOut"><part name="return" type="xsd:string"/></message><message name="helloWorldIn"/><message name="helloWorldOut"><part name="return" type="xsd:string"/></message><message name="welcomeMessageIn"><part name="color" type="xsd:string"/></message><message name="welcomeMessageOut"><part name="return" type="xsd:string"/></message><message name="getSessionIdIn"/><message name="getSessionIdOut"><part name="return" type="xsd:anyType"/></message></definitions>
Fichier: /pages/tutorials/webservice/helloworld-01-server.php
<?php /* * Use: http://YOUR_DOMAIN/tutorials/webservice/ * helloworld-01-server.wsdl?wsdl */
class Helloworld01Server extends WebSitePhpSoapServer { function __construct() { parent::__construct('Helloworld01'); } }
class Helloworld01 extends WebSitePhpSoapServerObject { private $login = ""; /** * setLogin * * @param string $login, the user login * @return string str, please set the return to be sure object is setting */ public function setLogin($login) { $this->login = $login; return ""; } /** * helloWorld * * @return string str, helloworld text */ public function helloWorld() { return "HelloWorld, ".$this->login." !!!"; } /** * welcomeMessage * * @param string $color, text color * @return string str, welcome text */ public function welcomeMessage($color) { return htmlentities("<font color=\"".$color."\">". "Welcome, ".$this->login." !!!</font>"); } } ?>
Tutoriel 3 : Webservice client with object
Fichier: /pages/tutorials/webservice/helloworld-02-client.php
<?php /* * Use: http://YOUR_DOMAIN/tutorials/webservice/ * helloworld-02-client.html */
require_once(dirname(__FILE__)."/MySoapableObject.class.php");
class Helloworld02Client extends Page { public function InitializeComponent() { parent::$PAGE_TITLE = "Webservice client with object"; // Init webservice $client = new WebSitePhpSoapClient( $this->getBaseLanguageURL(). "/tutorials/webservice/". "helloworld-02-server.wsdl?wsdl"); // test with a complex object $my_obj = new MySoapableObject(); $my_obj->setText("It's my object"); $obj_echo = $client->echoObject( new SoapVar($my_obj, SOAP_ENC_OBJECT)); $sub_text = $client->getObjectSubText( new SoapVar($my_obj, SOAP_ENC_OBJECT)); // display result message $this->render = new WSPObject($obj_echo, "<br/>", $sub_text); } } ?>
Fichier: /pages/tutorials/webservice/MySoapableObject.class.php
<?php require_once(dirname(__FILE__)."/MySubSoapableObject.class.php");
class MySoapableObject { private $text = ""; private $sub_object = null; public function setText($txt) { $this->text = $txt; $this->sub_object = new MySubSoapableObject(); $this->sub_object->setSubText($txt." [sub_object]"); } public function getText() { return $this->text; } public function getSubObject() { return $this->sub_object; } } ?>
Fichier: /pages/tutorials/webservice/MySubSoapableObject.class.php
<?php class MySubSoapableObject { private $sub_text = ""; public function setSubText($txt) { $this->sub_text = $txt; } public function getSubText() { return $this->sub_text; } } ?>
Tutoriel 4 : Webservice server with object (WSDL)
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Helloworld02" targetNamespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"><types><xsd:schema targetNamespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"><xsd:complexType name="MySoapableObject"><xsd:all/></xsd:complexType></xsd:schema></types><portType name="Helloworld02Port"><operation name="echoObject"><documentation>echoObject</documentation><input message="tns:echoObjectIn"/><output message="tns:echoObjectOut"/></operation><operation name="getObjectSubText"><documentation>getObjectSubText</documentation><input message="tns:getObjectSubTextIn"/><output message="tns:getObjectSubTextOut"/></operation><operation name="getSessionId"><documentation>Method getSessionId</documentation><input message="tns:getSessionIdIn"/><output message="tns:getSessionIdOut"/></operation></portType><binding name="Helloworld02Binding" type="tns:Helloworld02Port"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="echoObject"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl#echoObject"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></output></operation><operation name="getObjectSubText"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl#getObjectSubText"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></output></operation><operation name="getSessionId"><soap:operation soapAction="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl#getSessionId"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></output></operation></binding><service name="Helloworld02Service"><port name="Helloworld02Port" binding="tns:Helloworld02Binding"><soap:address location="https://www.website-php.com/fr/tutorials/webservice/helloworld-02-server.wsdl"/></port></service><message name="echoObjectIn"><part name="object" type="tns:MySoapableObject"/></message><message name="echoObjectOut"><part name="return" type="xsd:string"/></message><message name="getObjectSubTextIn"><part name="object" type="tns:MySoapableObject"/></message><message name="getObjectSubTextOut"><part name="return" type="xsd:string"/></message><message name="getSessionIdIn"/><message name="getSessionIdOut"><part name="return" type="xsd:anyType"/></message></definitions>
Fichier: /pages/tutorials/webservice/helloworld-02-server.php
<?php /* * Use: http://YOUR_DOMAIN/tutorials/webservice/ * helloworld-02-server.wsdl?wsdl */
require_once(dirname(__FILE__)."/MySoapableObject.class.php");
class Helloworld02Server extends WebSitePhpSoapServer { function __construct() { parent::__construct('Helloworld02'); } }
class Helloworld02 extends WebSitePhpSoapServerObject { /** * echoObject * * @param MySoapableObject $object, object * @return string str, object description */ public function echoObject($object) { return echo_r($object); } /** * getObjectSubText * * @param MySoapableObject $object, object * @return string str, get text from sub object */ public function getObjectSubText($object) { return $object->sub_object->sub_text; } } ?>
|
|
|
|
|