Building a SOAP Server with Zend_Soap_Server and Returning Arrays of ComplexTypes

ZendFramework is awesome but suffers from a peculiar lack of thorough examples and documentation.

To save you all some time scouring the internet fruitlessly, I will document how to use Zend_Soap_Server, and Zend_Soap_AutoDiscover in combination with Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex (try saying that really fast a few times!).

A Complete Example

No one ever put together a full example in the documentation, their blog posts, the official Zend samples or anywhere else I searched yesterday. It’s always snippets here and there, and they don’t fit together well. So let me save you some trouble. I figure your reaching this page means you’ve already passed the first test which is to know the classes you need, which is why the search brought you here :)

I’m binding my webservice to a class, as that would be the logical choice in most cases.

/* these are required for it all to work */
require("Zend/Soap/Server.php");
require("Zend/Soap/Wsdl.php");
require("Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php");
require("Zend/Soap/AutoDiscover.php");


/* my system makes use of a global prefix, feel free to do as needed */
$serviceURL = WWWPREFIX . '/webservices/myservice';


public class MyService {
     /**
     *
     * @param integer $UserID
     * @return array
     */
    function GetCoupons($UserID) {
        // do some work here
        $coupons = array(new Coupon(), new Coupon());
    }
}

// Generate WSDL relevant to code
if (isset($_GET['wsdl'])){
    $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
    $autodiscover->setClass('MyService');
    $autodiscover->handle();
} else {
    $server = new Zend_Soap_Server($serviceURL . "?wsdl");
    $server->setClass('MyService');
    $server->setObject(new MyService());
    $server->handle();
}

There are a few points of interest in the code block above (which is a completely functional service btw):

  • Notice the PHPDoc block above the function? If you don’t get that right, it won’t work at all
  • The return type of array because we’re returning an array of objects
  • The Zend_Soap_AutoDiscover bit at the bottom? That’ll auto-generate your WSDL for you

There, you’re done. It should all just work, complete with WSDL auto-generation. If you’re looking to make use of an existing WSDL file, you can use the secondary method of binding to methods/functions as outlined over at the official documentation on Zend_Soap_Server.

Say thank you Uncle Kevin :)

Make Your Band’s Album Cover Meme

The meme has been going around, and here’s my take — click to embiggen :)

Make your band's album cover meme

Make your band’s album cover meme:

  1. Go to Wikipedie’s special random page. The first random Wikipedia article you get is the name of your band.
  2. Go to Quotations Page’s random quotations page. The last four or five words of the very last quote on the page is the title of your first album.
  3. Go to Flickr’s explore the last seven days page. Third picture, no matter what it is, will be your album cover.
  4. Use Photoshop or similar to put it all together.
  5. Post it to FB with this text in the “caption” or “comment” and TAG the friends you want to join in.

Windows 7 Beta: Performance

After having used Vista for 2 years since I got my Dell, I’ve to say that it’s the slowest, buggiest version of Windows by far, even beating Windows ME for the title. Random lockups, sluggish UI, more random lockups, skipping audio, inability to delete/copy/move files in any reasonable amount of time (“Calculating remaining time” anyone?) to name a few of the problems that plagued Vista.

Windows 7 seem to have fixed all that. It just works (so far). None of the earlier problems are prevalent in 7. Speedy UI, effortless file operations, and no more skipping audio.

Let’s just hope it stays this way. Sad that I keep applying the (so far) qualifier to anything I have to say about Windows 7 — Microsoft has let me down too many times before.

I ♥ Amarok

I’ve been using Amarok on my GNOME desktop for years now, and loving it all the way. Recently I switched from Ubuntu to Fedora 10, and there’s no Amarok 1.4.x package — just the 2.x.

2.x is still nascent in terms of functionality, and every other Gtk based player I’ve tried (Banshee, Rhythmbox, Quod Libet, Exaile, BMPx, Listen etc.) don’t do it for me.

Long live Amarok 1.4.x. Whilst not quite what the authors of Amarok dream of — they want to turn it into a rich media platform, which is a nice idea — it was (and still is) amazingly good at what it was meant to do. Play and manage music.

P.S.: So good in fact, that I installed the dependencies and compiled the source for 1.4.10

Fedora 10

I’ve been running Fedora 10 since the Preview they released a while back and I must say that I’m incredibly impressed. After switching away from FC 3 to NoNameYet (which became Ubuntu) I’ve never looked back, being thoroughly impressed with it. Fedora has managed to make me reconsider, flaws and all.

First Impressions

It all starts when you boot the computer, and the extremely impressive start-up screen comes on. Not is it just animated, it’s of a blue sun with solar flares. I rebooted 2 or 3 times to just look at it. The show is all too soon over though, since Fedora 10 boots quite fast, almost matching Vista.

Freedom at a (really low) price

Now, Fedora is of course geared towards Freedom in the somewhat narrower than usual definition of software freedomFree software is a matter of the users’ freedom to run, copy, distribute, study, change and improve the software. Now this comes at a bit of a price for the typical user — you’ll have to spend quite a few minutes installing bits and pieces of proprietary, or otherwise un-free software like Nvidia drivers, MP3 playback, Java and so on. This isn’t particularly difficult thanks to RPMFusion.

Shiny new stuff

Fedora certainly does deliver on its promise of an up-to-date, easy to use desktop. The latest GNOME, and all the latest GNOME/Gtk/Mono applications are included in repositories, and are merely a click and some automated downloading away.

The bad

One complaint I do have about Fedora though is yum and PackageKit, the package management duo of choice. Compared to apt it is downright sluggish. All the waiting required makes me pre-plan(!) my package management.

Thoughts

I find that Fedora makes for an able desktop, wonderful development environment, and presents a good chance to contribute to the free software community. I haven’t even been trying and I’ve filed bugs and spent a couple of hours with the SELinux people discussing minor problems in the Preview. For some reason it seems to encourage me to give back shrug.

Maybe it’ll even convince me to start contributing code again…

Merging Kopete Contacts

For Google and my forgetful self:

To merge two contacts in Kopete into one, right click on the contact you wish to be added to the other, go to the protocol menu (usually last) and choose *Change Meta Contact*. Now search and pick the one you want to add it to.

I’ve had to redo my contact list a few times, and I’d been doing it to most braindead of ways: Removing contacts and readding them under the right meta-contact… Still this isn’t the most obvious of workflows.

openSUSE 11

The installation process for openSUSE 11 is quite impressive. LVM, package selection, desktop selection etc. were all top-notch without any hiccups (unlike my past experiences with Fedora). Post-installation set up was quite smooth as well, except for the part where I wanted a static IP — took 15 minutes to figure the GUI for that out. Seems more geared towards network administrators than end users.

I can’t say I expected the green to be pleasant, but I can’t complain — looks very nice. Overall, solid stuff.