Dilbert a day with PHP, SOAP using NUSOAP

Written by Shanx January 26th, 2001

Dilbert a day with PHP, SOAP using NUSOAP

Continue reading →
Close

A simple PHP script to view a daily Dilbert cartoon made available by United Media as a demonstration of SOAP technology. The WDSL service is usually made available by eSynaps.com.

This is a simple, straight-forward implementation of getting a Dilbert image everyday using PHP, SOAP (the NuSoap class from Deitrich Ayala) , and the Dilbert web service provided by eSynaps.com. Assuming that you have downloaded all the files of NUSOAP, the code is really simple:


<?

// Include the SOAP classes

require_once(‘nusoap.php’);

// No params required for this soap call

$param = array();

// Define path to server application

$serverpath =’http://www.esynaps.com/WebServices/DailyDiblert.asmx’;

// Define method namespace

$namespace=”http://tempuri.org/DailyDilbertImagePath”;

// Create client object

$client = new soapclient($serverpath);

// Create client object

$soapaction = ‘http://tempuri.org/DailyDilbertImagePath’;

// Make a SOAP request

$imgPath = $client->call(‘GetBriefings’,$param,

$namespace,$soapaction);

// Catch errors, or output error info

if (isset($fault))

{

// Fault is initialized. Something went wrong

echo ‘Error: ‘ . $fault;

}

else if ($imgPath == -1)

{

// Error encountered

echo ‘No image found yet.’;

}

else

{

// Otherwise output the result

echo ‘<p><img src=”‘ . $imgPath . ‘” alt=”Daily Dilbert” /></p>’;

}

// Kill object

unset($client);

?>

 

Click here to see today’s Daily Dilbert comic (on our main page)

Other useful resources

Posted in Miscellaneous

11 Comments

Tagged with

11 Comments

  1. Senen Botello says:

    Excelent short example

  2. Danny says:

    Thats pretty cool, can you post the server side code, I’m very interested to see how that works as well. Thanks.

  3. sniptools says:

    Danny, this *is* already server side code. It’s PHP.

  4. Daniele says:

    Shanx, this is not server side code, this is client side. We’re talking about web services, not about what php is :-)

  5. Matt says:

    IF you’ll notice, the server-side (SOAP server) is a .NET web service running on a totally different server. Chances are that they aren’t going to give you their code. This PHP just calls that service.

  6. makes says:

    Tried the code, but get this error:
    Parse error: syntax error, unexpected T_STRING in c:\wamp\www\soap\dilbert.php on line 13

    which is:
    $namespace=”http://tempuri.org/DailyDilbertImagePath“;;

    Any suggestions?
    Thanks.

  7. sniptools says:

    You seem to have two semi-colons to end that statement. Try removing it.

  8. Roberto Andrade says:

    I just get:

    Daily Dilbert

    I mean:

    <p><img src=”" alt=”Daily Dilbert” /></p>

    on Fedora Linux.

    Any sugestion?

    TIA
    Roberto

  9. Rajesh says:

    Hi

    I copied the code given above and pasted in my own created file called dilbert.php. Copied the nusoap class from the given path. but when i try to excute the script it shows nothing rather than a blank page without any error message.

    Please help me to sort it out.
    Thanks

  10. Geoff says:

    Roberto, I get the same thing. if I do a print_r on $imgPath, I get ”
    Array
    (
    [faultcode] => soap:Client
    [faultstring] => System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
    at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
    at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
    at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
    [detail] =>
    )

  11. holepuncher says:

    makes: Try making sure all your ‘ ” are not special characters.

    Once I fixed that though, I got the same problem as roberto.

Leave a Reply

Miscellaneous

I use the Nokia e61i as my mobile. Instead of my telco’s data plan (which offers me a meagre 1GB per month) I simply prefer to use my home wireless [...]

Continue reading →

View all

Web Tools

If you use Firefox (and if not, what are you waiting for?) you are familiar with useful extensions such as Video Downloader, which allow you to save local copies of [...]

Continue reading →

View all

Databases

This regexp worked for me. SELECT * FROM table WHERE NOT column ~ ( ‘^(‘|| $$[\09\0A\0D\x20-\x7E]|$$|| — ASCII $$[\xC2-\xDF][\x80-\xBF]|$$|| — non-overlong 2-byte $$\xE0[\xA0-\xBF][\x80-\xBF]|$$|| — excluding overlongs $$[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|$$|| — straight 3-byte [...]

Continue reading →

View all

Windows

So you’ve been visited by the much dreaded CRC — Cyclical Redundancy Check error, most likely encountered while copying files between hard disks. On Mac OSX, this will usually appear [...]

Continue reading →

View all

Mac OSX

A simple app ought to do it. Download iRinger. It’s a Windows app. If you’re on Mac, you’ll want to use it within a virtual machine, like Parallels or VMWare [...]

Continue reading →

View all

System Maintenance

I use the Nokia e61i as my mobile. Instead of my telco’s data plan (which offers me a meagre 1GB per month) I simply prefer to use my home wireless [...]

Continue reading →

View all

Wordpress

Among many new exciting features, WordPress 2.6 released the ability to store each and every revision of your posts, like an elaborate update history. Now this can be a pretty [...]

Continue reading →

View all

Audio/Video

Panic, the makers of some fantastic software such as Transmit or Panic, also have the most light-weight audio converter for the Mac OSX platform. It’s called Audion: get it here. [...]

Continue reading →

View all

iPhone

A simple app ought to do it. Download iRinger. It’s a Windows app. If you’re on Mac, you’ll want to use it within a virtual machine, like Parallels or VMWare [...]

Continue reading →

View all