public function handleWSDL($local) { header("Content-type: text/xml"); $autoDiscover = new AutoDiscover(new ArrayOfTypeSequence()); $autoDiscover->setClass('\\Tesoreria\\Service\\Tesoreria'); $autoDiscover->setUri(Constants::WSDL_URI_TESORERIA . $local); $autoDiscover->setServiceName('Tesoreria'); $autoDiscover->setOperationBodyStyle(array('use' => 'literal')); $wsdl = $autoDiscover->generate(); $wsdl = $wsdl->toDomDocument(); echo $wsdl->saveXML(); }
/** * Exibe o WSDL Description * @return xml WSDL */ private function handleWSDL() { // Objeto do Zend para leitura da classe $autodiscover = new Soap\AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex()); // Informa a classe $autodiscover->setClass($this->ws_class); // Informa a url do WS $autodiscover->setUri($this->ws_url); // Gera os dados $wsdl = $autodiscover->generate(); $wsdl = $wsdl->toDomDocument(); // Manda um cabecalho de XML @header('content-type:text/xml'); // Escreve em XML echo $wsdl->saveXML(); exit; }
/** * @Route("/server", name="soap_server") * * @param Request $request */ public function soapServerAction(Request $request) { if ($request->query->get('wsdl') !== null) { $complexTypeStrategy = new ArrayOfTypeComplex(); $autoDiscover = new AutoDiscover($complexTypeStrategy); $autoDiscover->setClass(SoapProcessor::class); $autoDiscover->setUri($this->generateUrl('soap_server', array(), UrlGeneratorInterface::ABSOLUTE_URL)); $wsdl = $autoDiscover->generate(); echo $wsdl->toXml(); exit; } $soapServerOptions = array('classmap' => array('BusinessObject' => BusinessObject::class)); $soapServer = new SoapServer($this->generateUrl('soap_server', array('wsdl' => ''), UrlGeneratorInterface::ABSOLUTE_URL), $soapServerOptions); $soapServer->setObject(new SoapProcessor()); $soapServer->handle(); exit; }
/** * {@inheritdoc} */ public function serve($params = null) { $uri = $params; if (!class_exists('SoapServer')) { throw new \Exception('SoapServer is required. Please enable this extension'); exit; } if (!class_exists('Zend\\Soap\\Server')) { throw new \Exception("Zend\\Soap\\Server is required. " . "Please install it using 'composer require zend/zend-soap'"); exit; } $serviceHandler = get_class($this->serviceHandler); $obj = new $serviceHandler($this->authentication, $this->connectionStrings, $this->logDir); if (null === $uri) { $uri = strtok($this->request->getUri(), '?'); $uri = dirname($uri) . '/' . basename($uri); } $response = new Response(); $response->headers->set('Access-Control-Allow-Headers', 'origin, content-type, accept'); $response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS'); $response->headers->set('Content-type', 'text/xml'); $cacheFile = dirname($_SERVER['SCRIPT_FILENAME']) . '/dbinstance.wsdl.xml'; if (isset($_GET['wsdl']) || isset($_GET['WSDL'])) { $xml = ''; if (file_exists($cacheFile)) { $xml = file_get_contents($cacheFile); } else { $autodiscover = new AutoDiscover(); $autodiscover->setUri($uri); $autodiscover->setClass($serviceHandler); $autodiscover->setServiceName('DBInstance'); $wsdl = $autodiscover->generate(); $xml = $wsdl->toXml(); $wsdl->dump($cacheFile); } $response->setContent($xml); return $response->send(); } $response->sendHeaders(); $server = new Server($uri . '?wsdl'); $server->setObject($obj); $server->handle(); }
public function testGetTypes() { $wsdlFilename = __DIR__ . '/TestAsset/GetTypesWsdlTest.wsdl'; $autodiscover = new AutoDiscover(); $autodiscover->setServiceName('ExampleService'); $autodiscover->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeComplex()); $autodiscover->setClass('\\ZendTest\\Soap\\TestAsset\\AutoDiscoverTestClass2'); $autodiscover->setUri('http://example.com'); $wsdl = $autodiscover->generate(); $wsdl->dump($wsdlFilename); $server = new Server($wsdlFilename); $server->setClass('\\ZendTest\\Soap\\TestAsset\\AutoDiscoverTestClass2'); $client = new Client\Local($server, $wsdlFilename); $soapClient = $client->getSoapClient(); $typesArray = $soapClient->__getTypes(); $this->assertCount(2, $typesArray); $count = 0; foreach ($typesArray as $element) { if (strpos($element, 'struct AutoDiscoverTestClass1') === 0 or strpos($element, 'AutoDiscoverTestClass1 ArrayOfAutoDiscoverTestClass1') === 0) { $count++; } } $this->assertEquals(2, $count, 'Invalid types'); unlink($wsdlFilename); }
/** * @group ZF-5736 */ public function testAmpersandInUrlIsCorrectlyEncoded() { $autodiscover = new AutoDiscover(); $autodiscover->setUri("http://example.com/?a=b&b=c"); $autodiscover->setClass('\\ZendTest\\Soap\\TestAsset\\Test'); $wsdl = $autodiscover->toXml(); $this->assertContains("http://example.com/?a=b&b=c", $wsdl); }
public function testSetNonStringNonZendUriUriThrowsException() { $server = new AutoDiscover(); $this->setExpectedException('\\Zend\\Soap\\Exception\\InvalidArgumentException', 'Argument to \\Zend\\Soap\\AutoDiscover::setUri should be string or \\Zend\\Uri\\Uri instance.'); $server->setUri(array("bogus")); }
/** * @expectedException \SoapFault */ public function testHandlePhpErrors() { if (headers_sent()) { $this->markTestSkipped('Cannot run ' . __METHOD__ . '() when headers have already been sent; enable output buffering to run this test'); return; } $wsdlFilename = __DIR__ . '/TestAsset/testHandlePhpErrors.wsdl'; $autodiscover = new AutoDiscover(); $autodiscover->setOperationBodyStyle(array('use' => 'literal')); $autodiscover->setBindingStyle(array('style' => 'document', 'transport' => 'http://schemas.xmlsoap.org/soap/http')); $autodiscover->setServiceName('ExampleService'); $autodiscover->setUri('http://example.com'); $autodiscover->setClass('\\ZendTest\\Soap\\TestAsset\\errorClass'); $wsdl = $autodiscover->generate(); $wsdl->dump($wsdlFilename); $server = new Server($wsdlFilename); $server->setClass('\\ZendTest\\Soap\\TestAsset\\errorClass'); $client = new \Zend\Soap\Client\Local($server, $wsdlFilename); $client->triggerError(); unlink($wsdlFilename); }