A Wander though Web Services

I’m sitting around on a Saturday, trying to cram enough about WebServices in PHP into my head to write a descent SoapServer/SoapClient presentation…when it hits me: “What do you mean I have to write the WSDL myself?!”
PHP 5’s new SOAP extension is just as amazing as the rest of the new XML extensions. If you are new to all of this, don’t fret. SOAP is just a defined way of accessing classes on another server. These classes are exposed as Web Services or (more specifically) SOAP Servers.

[size=larger][b]Hey! Where’s the [i]Wiz-dill[/i][/b][/size]
At the heart of a SOAP conversation is WSDL…the Web Services Definition Language. Now, I’m guessing because PHP is a “mostly” typeless language, the SoapServer extension requires you to provide the WSDL yourself. For the curious, yet uninitiated: WSDL is the definition of what your web service can do. Let’s look a little closer shall we?

For example, you might have a WSDL document that describes your new MicrowaveOven web service. This WSDL document contains the method names, arguments, expected types, etc of your MicrowaveOven.

With this WSDL a SoapClient would know exactly how to ask your $microwaveOven->getTimeRemaining() or be able to $microwaveOven->addMaterial($food). Because all of the conversation’s meta-data is contained in the SOAP Request and Response, it can all happen nearly automatically…depending on your library of choice.

[b][size=larger]The Brighter Future[/size][/b]
Now, if you happen to use .NET or ColdFusion MX, I’m sure you are snickering at the fact we don’t have a WSDL generator. Well, I’m not terribly concerned. Not only is the SoapServer class just getting off the ground, other options in the PHP Community are starting to appear.

For example, if this kind of thing interest you: be sure to keep an eye on Cerebral Cortex. This new PHP 5 framework is looking like an amazing offering. But, of note here are some of the SOAP Web Services Integration pieces. For example, take a look at their examples for their [url=http://synapticmedia.net/cerebralcortex/index.php?area=Main&page=CrtxSoapServer]Crtx_SOAP_Server[/url], [url=http://synapticmedia.net/cerebralcortex/index.php?area=Main&page=CrtxSoapAutoDiscover]Crtx_SOAP_AutoDiscover[/url] and [url=http://synapticmedia.net/cerebralcortex/index.php?area=Main&page=CrtxXmlWsdlCreator]Crtx_XML_WSDL[/url] classes.

The Crtx_SOAP_AutoDiscover uses your phpdoc comments to add the type hinting that is needed for your WSDL. Pretty clever really.

[b][size=larger]So, what about the SOAP talk?[/size][/b]
I think I’ll go ahead and hold off on the Web Services talk until there is some way to have something like (the as yet unreleased) crtx objects make the WSDL for me.

For those of you who were [i]really[/i] wanting to see how to write your own service, or query other SOAP services, I don’t want to leave you out in the cold. Zend has written an excellent article (with lots of pretty examples) on [url=http://www.zend.com/php5/articles/php5-SOAP.php]PHP 5’s SOAP extension[/url].

[b][size=larger]Go take a REST[/size][/b]
‘Course, you could always take the pragmatic aproach, and look at getting a little REST. It might not be as “cool” as SOAP, but it sure is fast and easy! Don’t decide on your webservices strategy until you have read Adam Trachtenberg’s [url=http://www.onlamp.com/pub/a/php/2003/10/30/amazon_rest.html]PHP Web Services Without SOAP[/url]

No, go write me some cool webservices to query up against. 🙂

Happy Coding!

14 thoughts on “A Wander though Web Services

  1. Re: A Wander though Web Services
    Sweet stuff.

    Is REST the thing that allows you to make dynamic php queries from javascript so that you don’t have to reload the page when you want new information to be shown?

    I would LOVE to get a talk on that.

    • Re: A Wander though Web Services
      So would I. 😉

      Seriously, it [i]can[/i] be used for that. However, REST is just a more formal way of using an url (and maybe POSTed variables) and getting back machine usable XML instead of just presentation ready html.

      For more of what you are interested in, check our Harry Fueck’s articles [url=http://www.sitepoint.com/blog-post-view.php?id=191776]Crouching Javascript, Hidden PHP Part 1[/url] and [url=http://www.sitepoint.com/blog-post-view.php?id=192138]Part 2[/url]. There’s a bunch of great information in there, as well as in the comments. Like the [url=http://www.ashleyit.com/rs/jsrs/select/php/select.php]farily cool[/url] [url=http://www.ashleyit.com/rs/]JSRS[/url].

    • Re: A Wander though Web Services
      Alright. The more I look into it, the more I want to do something with this. If you give me an idea of a mini-app or some examples I can build, I’ll do a presentation on it. Certainly not for [i]this[/i] Saturday, but maybe for the next one.

      All I can think of are the usual database-driven, cascading select box style forms. Well, that or an email client…but how many of us or going to write one when gmail is just utter email perfection?

      Oh, hey…that reminds me…

        • Re: A Wander though Web Services
          Alright…I’m sold. That would be pretty cool, and something that many people could use. Thanks for the idea you two.

          I’ve started writing up some examples (have a prototype working). If anyone wants to add any other example ideas before I go to bed tonight…they may just get their solution added to tomorrow’s meeting.

          Thanks again you two. As cool as what I was going to talk about is…it was just taking WAY too much time to explain (well, and cram it all into my head).

Leave a Reply

Your email address will not be published. Required fields are marked *