PHP Classes

Support for xsd:datetime?

Recommend this page to a friend!

      PHP WSDL Generator  >  All threads  >  Support for xsd:datetime?  >  (Un) Subscribe thread alerts  
Subject:Support for xsd:datetime?
Summary:DateTime object return causes empty WSDL file (no errors)
Messages:14
Author:Galmok
Date:2009-04-27 11:12:13
Update:2009-07-02 08:49:20
 
  1 - 10   11 - 14  

  1. Support for xsd:datetime?   Reply   Report abuse  
Picture of Galmok Galmok - 2009-04-27 11:12:13
I tried PHP WSDL Generator and while it seems to work well, I wasn't able to get DateTime objects to be supported. I tried this:

/**
* getCurrentDate: returns dateTime
*
* @return DateTime
*/
function getCurrentDate() {
return new DateTime();
}

When including this, the generated WSDL file is completely empty. No errors/warnings were given. Did I do it wrong?

  2. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Protung Dragos Protung Dragos - 2009-04-27 11:25:47 - In reply to message 1 from Galmok
Do you have any other PHP code included for generating the WSDL ?

  3. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Galmok Galmok - 2009-04-27 11:57:55 - In reply to message 2 from Protung Dragos
Yes, I have the code placed in two files:

This file hands out the WSDL file once generated (host name removed):

telekatwsdl.php:

<?php
require_once("WSDLCreator.php");
$test = new WSDLCreator("Telekat", "http://xxx.xxx.dk/soap/telekatwsdl.php");
$test->addFile("server.php");
$test->setClassesGeneralURL("http://xxx.xxx.dk/soap/");
$test->addURLToClass("TelekatService", "http://xxx.xxx.dk/soap/server.php");
$test->addURLToTypens("XMLCreator", "http://localhost/php2swdl");
$test->createWSDL();
$test->printWSDL(true); // print with headers
?>

server.php:

<?php
class TelekatService {
private $quotes = array("ibm" => 98.42);

/**
* getQuote:
*
* @param string $symbol
* @return float
*/
function getQuote($symbol) {
if (isset($this->quotes[$symbol])) {
return $this->quotes[$symbol];
} else {
throw new SoapFault("Server","Unknown Symbol '$symbol'.");
}
}

/**
* getCurrentDate: returns dateTime
*
* @return DateTime
*/
function getCurrentDate() {
return new DateTime();
}

/**
* getQuote: Check weight range of person. Returns true if good weight, false otherwise
*
* @param string $cpr
* @param float $weight
* @return boolean
*/
function isNormalWeight($cpr, $weight) {
// dummy
if ($weight < 70) {
return true;
} else {
return false;
}
}

}

$server = new SoapServer("http://xxx.xxx.dk/soap/telekatwsdl.php");
$server->setClass("TelekatService");
$server->handle();
?>


If I remove the getCurrentDate function, it all works.

I do have one question, though, I am not sure about the function of this line:

$test->addURLToTypens("XMLCreator", "http://localhost/php2swdl");

I don't have any page called php2swdl yet the server and testclient works anyway (except DateTime).

I am using PHP WSDL Generator - Version 1.2 b

  4. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Galmok Galmok - 2009-04-28 07:46:06 - In reply to message 3 from Galmok
Also, is it possible not to have the documenation be put in the wsdl file? I just noticed it now that the function documentation ends up in the wsdl file. :-P

  5. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Protung Dragos Protung Dragos - 2009-04-28 09:10:40 - In reply to message 1 from Galmok
Hi Galmok,

I've just added support for xsd:datetime
You also have an example for this.

I also added a method that removes the documentations of methods from the WSDL.
Just call $WSDLCreator->includeMethodsDocumentation(false); and you are all set.

By default the documentation will appear in the WSDL, so you are required to call that method in order to remove the documentation

Please make some tests and let me know if everything works ok.

Dragos

  6. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Galmok Galmok - 2009-04-28 11:04:27 - In reply to message 5 from Protung Dragos
Hi Dragos,

Thanks for the features.

I tested the no-doc feature and it works as advertised. :-)

I have however problems with the xsd:datetime extension. I don't think the problem is related to PHP WSDL Generator because the WSDL file looks good. It seems my php_mod is too old. :-(

Checking the PhP Bugs database, I found this:

bugs.php.net/bug.php?id=44383

Title: PHP DateTime not converted to xsd:datetime
Quote:"
[10 Dec 2008 1:44pm UTC] <email removed>

still not fixed in 5.2.6-0.dotdeb.1
"

And that was the last entry. I guess SoapServer doesn't support DateTime objects yet. I'll have to look at some other way to support datetime. :-/

I do appreciate your effort and will try to find a path through this jungle.

Galmok

  7. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Protung Dragos Protung Dragos - 2009-04-28 11:33:15 - In reply to message 6 from Galmok
I know about the bug.

The solution would be to make it as a string until SOAP fixes the problem.

You could also create a complex type of DateTime2 and use this class

class DateTime2 extends DateTime {
function __toString() {
return $this->format("Y-m-d H:i:s");
}
}

$datetime = new DateTime2();
print $datetime;


  8. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Galmok Galmok - 2009-04-28 12:29:42 - In reply to message 7 from Protung Dragos
Thank you for the proposed work-around, but I am not sure I can use this. I have to interface with a .NET application with working DatTime objects and the protocol should not have to work around bugs in SoapServer. :-/

I also checked PEAR:Soap but it also seems to have issues with DateTime objects.

NuSoap has other issues (like not being maintained).

I am somewhat lost now and may have to make a cludge, assuming a lot of stuff and manually extract the requires data from the XML. Or switch away from php altogether. Php just looked like it could work decently with SOAP, but without even DateTime support, I am not so sure anymore.. :-/

  9. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Galmok Galmok - 2009-04-28 12:51:22 - In reply to message 8 from Galmok
There is one issue with PHP WSDL Creator...

It doesn't seem to like multiple class definitions in a file. It will export all functions in all classes in the file pointed to by:

$test->addURLToClass("TelekatService", "http://xxx.xxx.dk/soap/server.php");

I put the DateTime2 class in the server.php file and ended up with an wsdl file containing __toString call as well as the other functions.

I expected only the class TelekatService to be exported to the WSDL file.

  10. Re: Support for xsd:datetime?   Reply   Report abuse  
Picture of Protung Dragos Protung Dragos - 2009-04-28 13:02:05 - In reply to message 9 from Galmok
You can ignore methods (or even classes) by using:

$WSDLCreator->ignoreMethod(array("classname"=>"methodname", "classname"=>"methodname2"));

Regarding message 3, you don't need the line:
$test->addURLToTypens("XMLCreator", "http://localhost/php2swdl");

This method is used in case you have a complex type and the PHP code for that type is not in the included files. In this case you define the URL for this type.

 
  1 - 10   11 - 14