Bonjour,
Je cherche a mettre en place un serveur soap simple en PHP5...
Voici deja mes fichiers :
client.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 <?php // Désactivation du cache WSDL ini_set('soap.wsdl_cache_enabled', 0); // Nouveau Client SOAP try { $xml = '<?xml version="1.0" encoding="UTF-8"?><OTA_PkgAvailRQ xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_PkgAvailRQ.xsd" Target="Production" Version="3.000" TimeStamp="2005-04-08T21:10:30" EchoToken="7656"> <POS> <Source AgentSine="ABC" AgentDutyCode="01234"> <RequestorID Type="4" ID="01234"> </RequestorID> </Source> </POS> <PackageRequest ID="K09104" TravelCode="42213" TourCode="MINAMA" ProductCode="K"> <DateRange Start="2007-06-20" Duration="P14N"/> </PackageRequest> <CustomerCounts> <CustomerCount Code="10" Quantity="2"/> <!-- Code 10 indicates an adult --> <CustomerCount Code="8" Quantity="1" Age="5"/> <!-- Code 8 indicates a child --> </CustomerCounts> </OTA_PkgAvailRQ>'; $client = new SoapClient('http://10.0.0.163/Soap/Server/fichier4.wsdl', array('trace' => 1, 'soap_version' => SOAP_1_1)); var_dump($client->__getFunctions()); echo "<hr/>"; $O = $client -> __getAvailability($xml); // Affichage du résultat echo $O->id_pkg ; echo "<hr/>"; } catch (SoapFault $fault) { echo $fault; } ?>
server.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 <?php // Désactivation du cache WSDL ini_set('soap.wsdl_cache_enabled', 0); // La classe qui va gérer les requètes SOAP class WebService { function getAvailability($id_pkg) { return array('id_pkg' => $id_pkg); } } // On tente d'instancier la classe soapServer // Si cela s'avère impossible, on lève une exception try { $server = new SoapServer('fichier4.wsdl', array('trace' => 1, 'soap_version' => SOAP_1_1)); // On définit la classe qui va gérer les requètes SOAP $server -> setclass('WebService'); } catch (Exception $e) { echo $e; } // La méthode POST a été utilisée pour appeller cette page. // On suppose donc qu'une requète a été envoyée, on la gère if ($_SERVER['REQUEST_METHOD'] == 'POST') { $server -> handle(); } // sinon, on affiche une liste des méthodes que peut gérer ce serveur else { echo '<strong>This SOAP server can handle following functions : </strong>'; echo '<ul>'; foreach($server -> getFunctions() as $func) { echo '<li>' , $func , '</li>'; } echo '</ul>'; } ?>
et fichier4.wsdl :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:webservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WebServices" targetNamespace="urn:webservice"> <message name="getAvailabilityRequest"> <part name="xmlin" type="xsd:string"/> </message> <message name="getAvailabilityResponse"> <part name="xmlout" type="xsd:string"/> </message> <portType name="AvailabilityPortType"> <operation name="getAvailability"> <input message="tns:getAvailabilityRequest"/> <output message="tns:getAvailabilityResponse"/> </operation> </portType> <binding name="AvailabilityBinding" type="tns:AvailabilityPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="getAvailability"> <soap:operation soapAction="urn:AvailabilityAction"/> <input> <soap:body use="encoded" namespace="urn:xmethods" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="encoded" namespace="urn:xmethods" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <service name="Webservice"> <port name="AvailabilityPort" binding="tns:AvailabilityBinding"> <soap:address location="http://10.0.0.163/Soap/Server/server.php"/> </port> </service> </definitions>
Et j'obtiens ce joli message d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 array(1) { [0]=> string(37) "string getAvailability(string $xmlin)" } SoapFault exception: [Client] Function ("__getAvailability") is not a valid method for this service in /var/www/Soap/Server/client.php:35 Stack trace: #0 [internal function]: SoapClient->__call('__getAvailabili...', Array) #1 /var/www/Soap/Server/client.php(35): SoapClient->__getAvailability('
Alors je ne comprends pas bien d'ou vient le probleme ?? Le fichier wsdl, surement, mais a quel niveau ??
Partager