Mam taki kontroler:

  1. <?php
  2.  
  3. namespace Soap\Controller;
  4.  
  5. use Zend\Mvc\Controller\AbstractActionController;
  6. use Zend\View\Model\ViewModel;
  7. use Zend\Soap\Server;
  8. use Zend\Soap\AutoDiscover;
  9.  
  10. /**
  11.  * Soap Controller
  12.  *
  13.  * @author
  14.  */
  15. class SoapController extends AbstractActionController {
  16.  
  17. public function indexAction() {
  18. $response = $this->getResponse();
  19. $response->getHeaders()->addHeaderLine('Location', $this->getRequest()->getBaseUrl() . '/404');
  20. $response->setStatusCode(404);
  21. }
  22.  
  23. public function addEmailAction() {
  24.  
  25. /* @var $request \Zend\Http\PhpEnvironment\Request */
  26. $request = $this->getRequest();
  27.  
  28. // var_dump($request->getUriString());
  29. if ($request->getQuery('wsdl') !== NULL) {
  30. $autodiscover = new AutoDiscover();
  31. $autodiscover->setClass('\Soap\Model\AddEmailService')
  32. ->setUri($request->getUriString())
  33. ->setServiceName('PhpMailQueueSoapService');
  34.  
  35. $xml = $autodiscover->generate()->toXML();
  36.  
  37. $response = $this->getResponse();
  38. // $response->setStatusCode(200);
  39. $response->setContent($xml);
  40. /* @var $headers \Zend\Http\Headers */
  41. $headers = $response->getHeaders();
  42. $headers->addHeaders(array('Content-Type' => 'application/wsdl+xml;charset=UTF-8'));
  43. // var_dump($headers); die(__FILE__ . __LINE__);
  44. return $response;
  45. }
  46. else {
  47. $urlString = $request->getUriString() . '?wsdl';
  48. $soap = new Server($urlString);
  49. $soap->setClass('\Soap\Model\AddEmailService');
  50. $soap->handle();
  51. }
  52. }
  53.  
  54. /**
  55.   * Test klienta SOAP. Do usuniecia.
  56.   */
  57. public function clientAction() {
  58.  
  59. }
  60.  
  61. }


Uruchamiając aplikację w przeglądarce pod adresem: http://localhost/PhpMailQueue/branches/ver.../add-email?wsdl

Dostaję następujący dokument WSDL:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/PhpMailQueue/branches/ver_1.0_soap/public/soap/add-email?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:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="PhpMailQueueSoapService" targetNamespace="http://localhost/PhpMailQueue/branches/ver_1.0_soap/public/soap/add-email?wsdl">
  3. <types>
  4. <xsd:schema targetNamespace="http://localhost/PhpMailQueue/branches/ver_1.0_soap/public/soap/add-email?wsdl"/>
  5. </types>
  6. <portType name="PhpMailQueueSoapServicePort"/>
  7. <binding name="PhpMailQueueSoapServiceBinding" type="tns:PhpMailQueueSoapServicePort">
  8. <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  9. </binding>
  10. <service name="PhpMailQueueSoapServiceService">
  11. <port name="PhpMailQueueSoapServicePort" binding="tns:PhpMailQueueSoapServiceBinding">
  12. <soap:address location="http://localhost/PhpMailQueue/branches/ver_1.0_soap/public/soap/add-email?wsdl"/>
  13. </port>
  14. </service>
  15. </definitions>


i wywołując: http://localhost/PhpMailQueue/branches/ver.../soap/add-email
dostaję XML z błędem:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  3. <SOAP-ENV:Body>
  4. <SOAP-ENV:Fault>
  5. <faultcode>Sender</faultcode>
  6. <faultstring>Invalid XML</faultstring>
  7. </SOAP-ENV:Fault>
  8. </SOAP-ENV:Body>
  9. </SOAP-ENV:Envelope>


Gdzie popełniam błąd?

Dodam, że to moja pierwsza przygoda ze SOAP, więc nie wiem gdzie mogłem popełnić błąd, a komunikat błędu i google niewiele pomagają.