diff options
author | wei <> | 2007-01-12 05:53:43 +0000 |
---|---|---|
committer | wei <> | 2007-01-12 05:53:43 +0000 |
commit | f7ca8c7ac8718899c1ab36513aaf3853a4514816 (patch) | |
tree | 3eae66f3578b84bc68c489538fd832b3f424ad05 | |
parent | 34d24de2f004df6ab096f4165eb31e16e70e76bb (diff) |
Fixed a number of SOAP bugs.
-rw-r--r-- | demos/quickstart/protected/pages/Services/SoapService.page | 63 | ||||
-rw-r--r-- | framework/3rdParty/WsdlGen/Wsdl.php | 17 | ||||
-rw-r--r-- | framework/3rdParty/WsdlGen/WsdlMessage.php | 4 | ||||
-rw-r--r-- | framework/3rdParty/WsdlGen/WsdlOperation.php | 14 | ||||
-rw-r--r-- | framework/Web/Services/TSoapService.php | 13 |
5 files changed, 91 insertions, 20 deletions
diff --git a/demos/quickstart/protected/pages/Services/SoapService.page b/demos/quickstart/protected/pages/Services/SoapService.page index 59042156..04dea07a 100644 --- a/demos/quickstart/protected/pages/Services/SoapService.page +++ b/demos/quickstart/protected/pages/Services/SoapService.page @@ -64,9 +64,70 @@ In order for the WSDL generator to generate WSDL for a SOAP service, the provide <li>return value: <tt>@return value-type description</tt></li>
</ul>
<p>
-Valid parameter and return types include: <tt>string</tt>, <tt>int</tt>, <tt>boolean</tt>, <tt>float</tt>, <tt>array</tt>, <tt>mixed</tt>, etc. You may also specify a class name as the type, which translates into a complex SOAP type.
+Valid parameter and return types include: <tt>string</tt>, <tt>int</tt>, <tt>boolean</tt>, <tt>float</tt>, <tt>array</tt>, <tt>mixed</tt>, etc. You may also specify a class name as the type, which translates into a complex SOAP type. For example, for a complex type <tt>Contact</tt>
</p>
+<com:TTextHighlighter Language="php" CssClass="source">
+class Contact
+{
+ /**
+ * @var string $name
+ * @soapproperty
+ */
+ public $name;
+
+ /**
+ * @var Address $address
+ * @soapproperty
+ */
+ public $address;
+}
+
+class Address
+{
+ /**
+ * @var string city
+ * @soapproperty
+ */
+ public $city;
+}
+
+class ContactManager
+{
+ /**
+ * @return Contact[] an array of contacts
+ * @soapmethod
+ */
+ function getAllContacts()
+ {
+ return array(new Contact);
+ }
+
+ /**
+ * @return Contact one contact
+ * @soapmethod
+ */
+ function getContact($name)
+ {
+ return new Contact;
+ }
+}
+</com:TTextHighlighter>
+<p>For a complex soap object, the properties of the object are specified with
+<tt>@soapproperty</tt> keyword in the property phpdocs. Furthermore, the
+propert's type name must be specified as <tt>@var type $name</tt> where <tt>type
+</tt> is any valid type in mentioned earlier.
+An array of complex objects can also be returned by adding a pair of
+enclosing square brackets after the type name. For example, to return an
+array of <tt>Contact</tt> type, we define <tt>@return Contact[] ...</tt>.
+</p>
+
+<div class="tip"><b class="note">Tip:</b>
+A very useful tool to test out your web services is the free tool
+<a href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=65a1d4ea-0f7a-41bd-8494-e916ebc4159c">WebServiceStudio 2.0</a>. It can invoke webmethods interactively. The user can provide a WSDL endpoint. On clicking button Get the tool fetches the WSDL, generates .NET proxy from the WSDL and displays the list of methods available. The user can choose any method and provide the required input parameters.
+The tool requires a MS .NET runtime to be installed.
+</div>
+
<p>
<tt>TSoapService</tt> may be configured and customized in several ways. In the example above, the <soap> element actually specifies a SOAP service using the default <tt>TSoapServer</tt> implementation. Attributes in <soap> are passed to <tt>TSoapServer</tt> as its initial property values. For example, the <tt>provider</tt> attribute initializes the <tt>Provider</tt> property of <tt>TSoapServer</tt>. By setting <tt>SessionPersistent</tt> to be true in <soap> element, the provider instance will persist within the user session. You may develop your own SOAP server class and use it by specifying the <tt>class</tt> attribute of <soap>.
</p>
diff --git a/framework/3rdParty/WsdlGen/Wsdl.php b/framework/3rdParty/WsdlGen/Wsdl.php index 4b94fbb4..1c754200 100644 --- a/framework/3rdParty/WsdlGen/Wsdl.php +++ b/framework/3rdParty/WsdlGen/Wsdl.php @@ -105,6 +105,7 @@ class Wsdl xmlns:tns="'.$this->targetNamespace.'" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"></definitions>'; $dom = new DOMDocument(); @@ -128,7 +129,7 @@ class Wsdl public function addTypes(DomDocument $dom) { if (!count($this->types)) return; - $types = $dom->createElement('types'); + $types = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:types'); $schema = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema'); $schema->setAttribute('targetNamespace', $this->targetNamespace); foreach($this->types as $type => $elements) @@ -139,10 +140,10 @@ class Wsdl { $complexContent = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent'); $restriction = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction'); - $restriction->setAttribute('base', 'SOAP-ENC:Array'); + $restriction->setAttribute('base', 'soap-enc:Array'); $attribute = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute'); - $attribute->setAttribute('ref', "SOAP-ENC:arrayType"); - $attribute->setAttribute('arrayType', 'tns:' . substr($type, 0, strlen($type) - 5) . '[]'); + $attribute->setAttribute('ref', "soap-enc:arrayType"); + $attribute->setAttribute('wsdl:arrayType', 'tns:' . substr($type, 0, strlen($type) - 5) . '[]'); $restriction->appendChild($attribute); $complexContent->appendChild($restriction); $complexType->appendChild($complexContent); @@ -183,7 +184,7 @@ class Wsdl */ protected function addPortTypes(DOMDocument $dom) { - $portType = $dom->createElement('portType'); + $portType = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:portType'); $portType->setAttribute('name', $this->serviceName.'PortType'); $this->definitions->appendChild($portType); @@ -199,7 +200,7 @@ class Wsdl */ protected function addBindings(DOMDocument $dom) { - $binding = $dom->createElement('binding'); + $binding = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:binding'); $binding->setAttribute('name', $this->serviceName.'Binding'); $binding->setAttribute('type', 'tns:'.$this->serviceName.'PortType'); @@ -222,10 +223,10 @@ class Wsdl */ protected function addService(DomDocument $dom) { - $service = $dom->createElement('service'); + $service = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:service'); $service->setAttribute('name', $this->serviceName.'Service'); - $port = $dom->createElement('port'); + $port = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:port'); $port->setAttribute('name', $this->serviceName.'Port'); $port->setAttribute('binding', 'tns:'.$this->serviceName.'Binding'); diff --git a/framework/3rdParty/WsdlGen/WsdlMessage.php b/framework/3rdParty/WsdlGen/WsdlMessage.php index 74165dae..4d044dd0 100644 --- a/framework/3rdParty/WsdlGen/WsdlMessage.php +++ b/framework/3rdParty/WsdlGen/WsdlMessage.php @@ -62,12 +62,12 @@ class WsdlMessage */ public function getMessageElement(DOMDocument $dom) { - $message = $dom->createElement('message'); + $message = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:message'); $message->setAttribute('name', $this->name); foreach ($this->parts as $part) { if (isset($part['name'])) { - $partElement = $dom->createElement('part'); + $partElement = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:part'); $partElement->setAttribute('name', $part['name']); $partElement->setAttribute('type', $part['type']); $message->appendChild($partElement); diff --git a/framework/3rdParty/WsdlGen/WsdlOperation.php b/framework/3rdParty/WsdlGen/WsdlOperation.php index ae561a16..20a10db8 100644 --- a/framework/3rdParty/WsdlGen/WsdlOperation.php +++ b/framework/3rdParty/WsdlGen/WsdlOperation.php @@ -81,13 +81,13 @@ class WsdlOperation */ public function getPortOperation(DomDocument $dom) { - $operation = $dom->createElement('operation'); + $operation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:operation'); $operation->setAttribute('name', $this->operationName); - $documentation = $dom->createElement('documentation', htmlentities($this->documentation)); - $input = $dom->createElement('input'); + $documentation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:documentation', htmlentities($this->documentation)); + $input = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:input'); $input->setAttribute('message', 'tns:'.$this->inputMessage->getName()); - $output = $dom->createElement('output'); + $output = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:output'); $output->setAttribute('message', 'tns:'.$this->outputMessage->getName()); $operation->appendChild($documentation); @@ -107,7 +107,7 @@ class WsdlOperation */ public function getBindingOperation(DomDocument $dom, $namespace, $style='rpc') { - $operation = $dom->createElement('operation'); + $operation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:operation'); $operation->setAttribute('name', $this->operationName); $soapOperation = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/soap/', 'soap:operation'); @@ -115,8 +115,8 @@ class WsdlOperation $soapOperation->setAttribute('soapAction', $namespace.'#'.$method); $soapOperation->setAttribute('style', $style); - $input = $dom->createElement('input'); - $output = $dom->createElement('output'); + $input = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:input'); + $output = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/', 'wsdl:output'); $soapBody = $dom->createElementNS('http://schemas.xmlsoap.org/wsdl/soap/', 'soap:body'); $soapBody->setAttribute('use', 'encoded'); diff --git a/framework/Web/Services/TSoapService.php b/framework/Web/Services/TSoapService.php index 05e62171..2d161f15 100644 --- a/framework/Web/Services/TSoapService.php +++ b/framework/Web/Services/TSoapService.php @@ -294,7 +294,7 @@ class TSoapServer extends TApplicationComponent */ public function __construct() { - $this->_classMap=new TAttributeCollection; + $this->_classMap=new TMap;//TAttributeCollection; } /** @@ -332,7 +332,14 @@ class TSoapServer extends TApplicationComponent } else $server=$this->createServer(); - $server->handle(); + try + { + $server->handle(); + } + catch (Exception $e) + { + $server->fault("SERVER", $e->getMessage(),"", $e->__toString(), ''); + } } /** @@ -340,6 +347,8 @@ class TSoapServer extends TApplicationComponent */ protected function createServer() { + if($this->getApplication()->getMode()===TApplicationMode::Debug) + ini_set("soap.wsdl_cache_enabled",0); return new SoapServer($this->getWsdlUri(),$this->getOptions()); } |