Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: zapytanie soap
Forum PHP.pl > Forum > PHP > Object-oriented programming
christof
Witam,
zaczynam się bawić soap ale nie wiem do końca czy dobrze to ugryzłem napisałem taki kodzik :

  1. <?php
  2. class TestWS extends SoapClient{
  3. // Dołączenie pakietu NuSOAP
  4.  
  5. private $WSDL = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL';
  6.  
  7. public function __construct(){
  8. parent::SoapClient($this->WSDL);
  9. }
  10.  
  11.  
  12.  
  13. // Utworzenie obiektu klienta SOAP
  14.  
  15.  
  16.  
  17. public function WeatherReturn($city){
  18. $query = new GetCityWeatherByZIPResponse();
  19. $query->city = $city;
  20.  
  21. return $this->__soapCall('WeatherReturn', array($query));
  22. // lub
  23. //return $this->WeatherReturn($query);
  24. }
  25.  
  26. }
  27. class GetCityWeatherByZIPResponse{
  28.  
  29. public $city;
  30. }
  31.  
  32. class WeatherReturn{
  33.  
  34. public $State;
  35.  
  36.  
  37. public $WeatherStationCit;
  38.  
  39.  
  40. public $Temperature;
  41. }
  42. $test_ws = new TestWS();;
  43. $city = 'warszawa';
  44.  
  45.  
  46. $call = $test_ws->WeatherReturn($city);
  47.  
  48. print_r("miasto: ".$city." ma temp ".$call->Temperature." i".$call->State);
  49.  
  50.  
  51. ?>
  52.  



ale cały czas wywala mi błąd :

Kod
Fatal error: Uncaught SoapFault exception: [Client] Function ("WeatherReturn") is not a valid method for this service in E:\serwer\index.php:39 Stack trace: #0 E:\serwer\index.php(39): SoapClient->__soapCall('WeatherReturn', Array) #1 E:\serwer\index.php(72): TestWS->WeatherReturn('warszawa') #2 {main} thrown in E:\serwer\index.php on line 39




Kurczę już nie wiem jak to zrobić mógł by mi ktoś z obecnych pomóc zrobić nowe zapytanie ale do wsdl tego : http://www.webservicex.com/globalweather.asmx?WSDL albo na podstawie tego mojego kodu był bym wdzięczny jakby ktoś mi w tym pomógł

Przepraszam że post za postem ale nie chcę robić bałaganu , zrobiłem kod na ten drugi wsdl :

  1. <?php
  2. class TestWS extends SoapClient{
  3.  
  4. private $WSDL = 'http://www.webservicex.com/globalweather.asmx?WSDL ';
  5.  
  6. public function __construct(){
  7. parent::SoapClient($this->WSDL);
  8. }
  9.  
  10. /**
  11. * @return Pobierz_produkt_OUT
  12. * @param int $id_produktu
  13. */
  14. public function GetWeather($city,$country){
  15. $query = new GetWeatherSoapIn();
  16. $query->CityName = $city;
  17. $query->CountryName = $country;
  18.  
  19. return $this->__soapCall('GetWeather', array($query));
  20. // lub
  21. //return $this->Pobierz_produkt($query);
  22. }}
  23. $test_ws = new TestWS();
  24. $city = 'warszawa';
  25. $country = 'Poland';
  26.  
  27.  
  28. $call = $test_ws->GetWeather($city,$country);
  29. var_dump($call);
  30. //print_r("Pordukt o id ".$city." ma nazwę ".$call->nazwa." i kosztuje ".$call->cena." PLN");
  31.  
  32. ?>



i teraz mi taki błąd wychodzi , tak jakby w ogóle sie nie chciał połączyć :
Kod
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.webservicex.com/globalweather.asmx?WSDL ' : Premature end of data in tag html line 3 in E:\serwer\index.php:7 Stack trace: #0 E:\serwer\index.php(7): SoapClient->SoapClient('http://www.webs...') #1 E:\serwer\index.php(23): TestWS->__construct() #2 {main} thrown in E:\serwer\index.php on line 7



mam nadzieję , że ktoś pomoże smile.gif
Pyton_000
Generalnie jeżeli dziedziczysz po SoapClient tak jak u Ciebie to możesz wykonywać metody bezpośrednio czyli np:
  1. $this->WeatherReturn($query);


Dodatkowo zerknij na metody
Kod
public array __getFunctions ( void )
public string __getLastRequest ( void )
public string __getLastRequestHeaders ( void )
public string __getLastResponse ( void )
public string __getLastResponseHeaders ( void )
christof
dzięki trochę przejrzałem to smile.gif
ale teraz mi za to taki błąd wyskakuje
Kod
Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Procedure or function 'getWeather' expects parameter '@CountryName', which was not supplied. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.D in E:\serwer\1\index.php on line 8



a oto moja 8 linijka bo chyba zle robie odwołanie do funkcji GetWeather tylko nie wiem jak ona ma wygladać jak funkcja oczekuje 2 parametrów. a oto mój kod :
  1. echo $soap-> GetWeather('katowice','poland');
  2.  
Pyton_000
przekazujesz parametry w tablicy z kluczami w formie oczekiwanych zmiennych
np
  1. $soap->GetWeather(array('CountryName' => 'sss', 'drugi' => 'ddd'));
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.