Mam taki kontroler:
<?php
namespace Soap\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Soap\Server;
use Zend\Soap\AutoDiscover;
/**
* Soap Controller
*
* @author
*/
class SoapController extends AbstractActionController {
public function indexAction() {
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Location', $this->getRequest()->getBaseUrl() . '/404');
$response->setStatusCode(404);
}
public function addEmailAction() {
/* @var $request \Zend\Http\PhpEnvironment\Request */
$request = $this->getRequest();
// var_dump($request->getUriString());
if ($request->getQuery('wsdl') !== NULL) {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('\Soap\Model\AddEmailService')
->setUri($request->getUriString())
->setServiceName('PhpMailQueueSoapService');
$xml = $autodiscover->generate()->toXML();
$response = $this->getResponse();
// $response->setStatusCode(200);
$response->setContent($xml);
/* @var $headers \Zend\Http\Headers */
$headers = $response->getHeaders();
$headers->addHeaders(array('Content-Type' => 'application/wsdl+xml;charset=UTF-8')); // var_dump($headers); die(__FILE__ . __LINE__);
return $response;
}
else {
$urlString = $request->getUriString() . '?wsdl';
$soap = new Server($urlString);
$soap->setClass('\Soap\Model\AddEmailService');
$soap->handle();
}
}
/**
* Test klienta SOAP. Do usuniecia.
*/
public function clientAction() {
}
}
Uruchamiając aplikację w przeglądarce pod adresem:
http://localhost/PhpMailQueue/branches/ver.../add-email?wsdlDostaję następujący dokument WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<types>
<xsd:schema targetNamespace="http://localhost/PhpMailQueue/branches/ver_1.0_soap/public/soap/add-email?wsdl"/>
</types>
<portType name="PhpMailQueueSoapServicePort"/>
<binding name="PhpMailQueueSoapServiceBinding" type="tns:PhpMailQueueSoapServicePort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
</binding>
<service name="PhpMailQueueSoapServiceService">
<port name="PhpMailQueueSoapServicePort" binding="tns:PhpMailQueueSoapServiceBinding">
<soap:address location="http://localhost/PhpMailQueue/branches/ver_1.0_soap/public/soap/add-email?wsdl"/>
</port>
</service>
</definitions>
i wywołując:
http://localhost/PhpMailQueue/branches/ver.../soap/add-emaildostaję XML z błędem:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>Sender</faultcode>
<faultstring>Invalid XML</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</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ą.