/** * Add a Single or Multiple Functions to the WSDL * * @param string $function Function Name * @param string $namespace Function namespace - Not Used */ public function addFunction($function, $namespace = '') { static $port; static $operation; static $binding; if (!is_array($function)) { $function = (array) $function; } $uri = $this->getUri(); if (!$this->_wsdl instanceof WSDL\WSDL) { $parts = explode('.', basename($_SERVER['SCRIPT_NAME'])); $name = $parts[0]; $wsdl = new WSDL\WSDL($name, $uri, $this->_strategy); // The wsdl:types element must precede all other elements (WS-I Basic Profile 1.1 R2023) $wsdl->addSchemaTypeSection(); $port = $wsdl->addPortType($name . 'Port'); $binding = $wsdl->addBinding($name . 'Binding', 'tns:' . $name . 'Port'); $wsdl->addSoapBinding($binding, $this->_bindingStyle['style'], $this->_bindingStyle['transport']); $wsdl->addService($name . 'Service', $name . 'Port', 'tns:' . $name . 'Binding', $uri); } else { $wsdl = $this->_wsdl; } foreach ($function as $func) { $method = $this->_reflection->reflectFunction($func); $this->_addFunctionToWSDL($method, $wsdl, $port, $binding); } $this->_wsdl = $wsdl; }
function testAddSoapBinding() { $wsdl = new WSDL\WSDL('MyService', 'http://localhost/MyService.php'); $wsdl->addPortType('myPortType'); $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType'); $wsdl->addSoapBinding($binding); $wsdl->addBindingOperation($binding, 'operation1'); $wsdl->addBindingOperation($binding, 'operation2', array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")); $this->assertEquals($this->sanitizeWSDLXmlOutputForOsCompability($wsdl->toXml()), '<?xml version="1.0"?>' . '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" ' . 'xmlns:tns="http://localhost/MyService.php" ' . '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:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . 'name="MyService" targetNamespace="http://localhost/MyService.php">' . '<portType name="myPortType"/>' . '<binding name="MyServiceBinding" type="myPortType">' . '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>' . '<operation name="operation1"/>' . '<operation name="operation2">' . '<input>' . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>' . '</input>' . '<output>' . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>' . '</output>' . '</operation>' . '</binding>' . '</definitions>'); $wsdl1 = new WSDL\WSDL('MyService', 'http://localhost/MyService.php'); $wsdl1->addPortType('myPortType'); $binding = $wsdl1->addBinding('MyServiceBinding', 'myPortType'); $wsdl1->addSoapBinding($binding, 'rpc'); $wsdl1->addBindingOperation($binding, 'operation1'); $wsdl1->addBindingOperation($binding, 'operation2', array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"), array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")); $this->assertEquals($this->sanitizeWSDLXmlOutputForOsCompability($wsdl1->toXml()), '<?xml version="1.0"?>' . '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" ' . 'xmlns:tns="http://localhost/MyService.php" ' . '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:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . 'name="MyService" targetNamespace="http://localhost/MyService.php">' . '<portType name="myPortType"/>' . '<binding name="MyServiceBinding" type="myPortType">' . '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>' . '<operation name="operation1"/>' . '<operation name="operation2">' . '<input>' . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>' . '</input>' . '<output>' . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>' . '</output>' . '</operation>' . '</binding>' . '</definitions>'); }