function testAddPortOperation() { $wsdl = new Wsdl('MyService', 'http://localhost/MyService.php'); $portType = $wsdl->addPortType('myPortType'); $wsdl->addPortOperation($portType, 'operation1'); $wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response'); $wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault'); $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">' . '<operation name="operation1"/>' . '<operation name="operation2">' . '<input message="tns:operation2Request"/>' . '<output message="tns:operation2Response"/>' . '</operation>' . '<operation name="operation3">' . '<input message="tns:operation3Request"/>' . '<output message="tns:operation3Response"/>' . '<fault message="tns:operation3Fault"/>' . '</operation>' . '</portType>' . '</definitions>'); }
public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array()) { Assert::thatArgumentNotNull('definition', $definition); $options = array_merge(array('endpoint' => ''), $options); $this->definition = $definition; $wsdl = new Wsdl($definition->getName(), $definition->getNamespace()); $port = $wsdl->addPortType($this->getPortTypeName()); $binding = $wsdl->addBinding($this->getBindingName(), 'tns:' . $this->getPortTypeName()); $wsdl->addSoapBinding($binding, 'rpc'); $wsdl->addService($this->getServiceName(), $this->getPortName(), 'tns:' . $this->getBindingName(), $options['endpoint']); foreach ($definition->getMethods() as $method) { $requestParts = array(); $responseParts = array(); foreach ($method->getArguments() as $argument) { $requestParts[$argument->getName()] = $wsdl->getType($argument->getType()->getPhpType()); } if ($method->getReturn() !== null) { $responseParts['return'] = $wsdl->getType($method->getReturn()->getPhpType()); } $wsdl->addMessage($this->getRequestMessageName($method), $requestParts); $wsdl->addMessage($this->getResponseMessageName($method), $responseParts); $portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' . $this->getRequestMessageName($method), 'tns:' . $this->getResponseMessageName($method)); $portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts))); $bindingInput = array('parts' => implode(' ', array_keys($requestParts)), 'use' => 'literal', 'namespace' => $definition->getNamespace(), 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'); $bindingOutput = array('parts' => implode(' ', array_keys($responseParts)), 'use' => 'literal', 'namespace' => $definition->getNamespace(), 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'); $bindingOperation = $wsdl->addBindingOperation($binding, $method->getName(), $bindingInput, $bindingOutput); $wsdl->addSoapOperation($bindingOperation, $this->getSoapOperationName($method)); } $this->definition = null; $wsdl->toDomDocument()->formatOutput = true; return $wsdl->toXml(); }
/** * Add an operation to port type. * * @param DOMElement $portType * @param string $name Operation name * @param string|bool $input Input Message * @param string|bool $output Output Message * @param string|bool|array $fault Message name OR array('message' => ..., 'name' => ...) * @return object The new operation's XML_Tree_Node */ public function addPortOperation($portType, $name, $input = false, $output = false, $fault = false) { $operation = parent::addPortOperation($portType, $name, $input, $output, false); if (is_array($fault)) { $isMessageValid = isset($fault['message']) && is_string($fault['message']) && strlen(trim($fault['message'])); $isNameValid = isset($fault['name']) && is_string($fault['name']) && strlen(trim($fault['name'])); if ($isNameValid && $isMessageValid) { $node = $this->toDomDocument()->createElement('fault'); $node->setAttribute('name', $fault['name']); $node->setAttribute('message', $fault['message']); $operation->appendChild($node); } } return $operation; }