Bonjour,
j'apprend SOAP avec PHP 5 sur windows et je suis confronté à un probème :
Voici mes sources :
mon fichier de déclaration du service :mon fichier 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
33
34
35
36
37
38
39
40
41
42
43
44 <?php $wsdl = "Webservices.wsdl"; //déclaration de la classe etang class etang{ function GetWeather($lieu){ $o = new StdClass; $o->UTC = "2006.07.05 1500 UTC"; $o->Local = "2006.07.05 1700 UTC+2"; $o->Barometre = "1015 hPa"; $o->Temperature = "33 C"; $o->DewPoint = "15 C"; $o->Wind = "18 KT"; $o->Direction = "S"; $o->Gust = "NULL"; $o->Sky = "Sunny"; $o->RelativeHumidity = "34 %"; $o->ReportStatus = "Success"; return $o; } // function GetForecast($lieu){ $o = new StdClass; $o->UTC = "2006.07.05 1400 UTC"; $o->Local = "2006.07.05 1600 UTC+2"; $o->Valid = "2006.07.05 1500 UTC TO 2006.07.05 2400 UTC". $o->Direction = "SSE"; $o->Gust = "NULL"; $o->Sky = "Sunny"; $o->ReportStatus = "Success"; return $o; } } // try{ $server = new SoapServer($wsdl); $server->setClass("etang"); $server->setPersistence(SOAP_PERSISTENCE_SESSION); } catch(SoapFault $e){ die("Server error"); } $server->handle(); ?>et mon fichier de déclaration du client :
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<?xml version="1.0" encoding="UTF-8"?> <!-- This file has been generated by UML2PHP5 UML2PHP5 is free and released under GPL Copyright KDO kdo@zpmag.com UML2PHP5 : uml2php5.zpmag.com --><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="GetWeatherRequest"> <part name="lieu" type="xsd:string"/> </message> <message name="GetForecastRequest"> <part name="lieu" type="xsd:string"/> </message> <portType name="etangPortType"> <operation name="GetWeather"> <input message="tns:GetWeatherRequest"/> </operation> <operation name="GetForecast"> <input message="tns:GetForecastRequest"/> </operation> </portType> <binding name="etangBinding" type="tns:etangPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="GetWeather"> <soap:operation soapAction="urn:etangAction"/> <input> <soap:body use="encoded" namespace="urn:xmethods" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> <operation name="GetForecast"> <soap:operation soapAction="urn:etangAction"/> <input> <soap:body use="encoded" namespace="urn:xmethods" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> </binding> <service name="Webservice"> <port name="etangPort" binding="tns:etangBinding"> <soap:address location="http://127.0.0.1/dia/soap_server.php?action=etang"/> </port> </service> </definitions>
Alors, j'aimerai savoir comment faire pour appeler la méthode GetWeather étant donné que j'ai décléré mes méthodes dans une classes ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?php $wsdl = "Webservices.wsdl"; //creation du client $client = new SoapClient($wsdl); //if($bulletin_meteo = new $client->etang()) // echo "opération réussi"; if(!$temperature = $client->GetWeather("Paris")){ die("Error"); } echo "La température est ", $temperature->Temperature; ?>
Merci !
Partager