Mam dziwny problem z SOAP. Moj plik SchoolAPI wyglada nastepująco.

  1. <?php
  2. require_once('../require/constants.php');
  3. require_once('../require/connection.inc.php');
  4.  
  5. class SchoolAPI{
  6. private $dbh;
  7.  
  8. public function __construct()
  9. {
  10. $this->dbh = new PDO(DRIVER.':host='.HOST.';dbname='.DB, USER, PASSWORD);
  11. }
  12.  
  13. //funkcja zwracajaca wszystkie przedmioty
  14. public function getSubjects(){
  15. $sth = $this->dbh->prepare(' SELECT id, nazwa_pl
  16. FROM przedmioty');
  17. $sth->execute();
  18.  
  19. return $sth->fetchAll(PDO::FETCH_NUM);
  20. //return array(array("1", "przedmiot1"),array("2", "przedmiot2"));
  21. }
  22.  
  23. //funkcja zwracajaca wszystkie klasy
  24. public function getClasses(){
  25. $sth = $this->dbh->prepare(' SELECT id, nazwa
  26. FROM klasy');
  27. $sth->execute();
  28. return $sth->fetchAll(PDO::FETCH_NUM);
  29. //return array(array("1", "klasa1"),array("2", "klasa2"));
  30. }
  31.  
  32. }
  33. ini_set("soap.wsdl_cache_enabled", "0");
  34. $server = new SoapServer("SchoolAPI.wsdl");
  35. $server->setClass("SchoolAPI");
  36. $server->handle();
  37. ?>


plik wsdl nosi nazwe SchoolAPI.wsdl i wyglada nastepujaco

  1. <wsdl:definitions
  2. xmlns="http://schemas.xmlsoap.org/wsdl/"
  3. xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  4. xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  5. xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  6. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  7. xmlns:tns="http://schema.example.com"
  8. targetNamespace="http://schema.example.com" >
  9.  
  10. <wsdl:types>
  11. <xsd:schema targetNamespace="http://schema.example.com">
  12. <xsd:complexType name="myarry2">
  13. <xsd:sequence>
  14. <xsd:element minOccurs="0" maxOccurs="unbounded" name="row" nillable="true" type="xsd:string" />
  15. </xsd:sequence>
  16. </xsd:complexType>
  17. </xsd:schema>
  18. <xsd:schema targetNamespace="http://schema.example.com">
  19. <xsd:complexType name="myarray">
  20. <xsd:sequence>
  21. <xsd:element minOccurs="0" maxOccurs="unbounded" name="table" nillable="true" type="tns:myarry2" />
  22. </xsd:sequence>
  23. </xsd:complexType>
  24. </xsd:schema>
  25. </wsdl:types>
  26.  
  27. <wsdl:message name="getSubjectsRequest"></wsdl:message>
  28. <wsdl:message name="getSubjectsResponse">
  29. <part name="getSubjectsReturn" type="tns:myarray"/>
  30. </wsdl:message>
  31.  
  32. <wsdl:message name="getClassesRequest"></wsdl:message>
  33. <wsdl:message name="getClassesResponse">
  34. <part name="getClassesReturn" type="tns:myarray"/>
  35. </wsdl:message>
  36.  
  37. <wsdl:portType name="SchoolAPIPortType">
  38. <wsdl:operation name="getSubjects">
  39. <wsdl:input message="tns:getSubjectsRequest"/>
  40. <wsdl:output message="tns:getSubjectsResponse"/>
  41. </wsdl:operation>
  42.  
  43. <wsdl:operation name="getClasses">
  44. <wsdl:input message="tns:getClassesRequest"/>
  45. <wsdl:output message="tns:getClassesResponse"/>
  46. </wsdl:operation>
  47. </wsdl:portType>
  48.  
  49. <wsdl:binding name="SchoolAPIBinding" type="tns:SchoolAPIPortType">
  50. <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
  51. <wsdl:operation name="getSubjects">
  52. <soap:operation soapAction="urn:SchoolAPI/getSubjects" style="document"/>
  53. <wsdl:input> <soap:body use="literal"/></wsdl:input>
  54. <wsdl:output><soap:body use="literal"/></wsdl:output>
  55. </wsdl:operation>
  56. <wsdl:operation name="getClasses">
  57. <soap:operation soapAction="urn:SchoolAPI/getClasses" style="document"/>
  58. <wsdl:input> <soap:body use="literal"/></wsdl:input>
  59. <wsdl:output><soap:body use="literal"/></wsdl:output>
  60. </wsdl:operation>
  61. </wsdl:binding>
  62.  
  63. <wsdl:service name="SchoolAPI">
  64. <wsdl:port name="SchoolAPIPort" binding="tns:SchoolAPIBinding">
  65. <soap:address location="http://localhost:82/myschool/webservices/SchoolAPI.php" />
  66. </wsdl:port>
  67. </wsdl:service>
  68. </wsdl:definitions>


Problem polega na tym ze poprawne dane zwraca zawsze tylko pierwsza funkcja znajdujaca sie w sekcji <wsdl:binding> w tym przykladzie
poprawne dane zwróci tylko funkcja getSubjects a funkcja getClasses zwroci null. Gdy zamienimi kolejnoscia operacje w sekcji bindings w ten sposob:

  1. <wsdl:binding name="SchoolAPIBinding" type="tns:SchoolAPIPortType">
  2. <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
  3. <wsdl:operation name="getClasses">
  4. <soap:operation soapAction="urn:SchoolAPI/getClasses" style="document"/>
  5. <wsdl:input> <soap:body use="literal"/></wsdl:input>
  6. <wsdl:output><soap:body use="literal"/></wsdl:output>
  7. </wsdl:operation>
  8. <wsdl:operation name="getSubjects">
  9. <soap:operation soapAction="urn:SchoolAPI/getSubjects" style="document"/>
  10. <wsdl:input> <soap:body use="literal"/></wsdl:input>
  11. <wsdl:output><soap:body use="literal"/></wsdl:output>
  12. </wsdl:operation>
  13. </wsdl:binding>


to poprawne dane zwroci funkcja getClasses a funkcja getSubjects zwroci null. Czy ktos wie o co tu chodzi? Bo mi juz braknie pomyslow jak to rozwiazac.

Problem rozwiązany. Oto rozwiązanie:

  1. <wsdl:message name="getSubjectsRequest">
  2. <part name="getSubjectsReq" type="xsd:string" />
  3. </wsdl:message>
  4. <wsdl:message name="getSubjectsResponse">
  5. <part name="getSubjectsReturn" type="tns:myarray"/>
  6. </wsdl:message>
  7. <wsdl:message name="getClassesRequest">
  8. <part name="getClassesReq" type="xsd:string" />
  9. </wsdl:message>
  10. <wsdl:message name="getClassesResponse">
  11. <part name="getClassesReturn" type="tns:myarray"/>
  12. </wsdl:message>


Wygląda na to że Message Request nie moga być puste .