Dilbert a day with PHP, SOAP using NUSOAP

A sim­ple PHP script to view a daily Dil­bert car­toon made avail­able by United Media as a demon­stra­tion of SOAP tech­nol­ogy. The WDSL ser­vice is usu­ally made avail­able by eSynaps.com.

This is a sim­ple, straight-forward imple­men­ta­tion of get­ting a Dil­bert image every­day using PHP, SOAP (the NuSoap class from Deitrich Ayala) , and the Dil­bert web ser­vice pro­vided by eSynaps.com. Assum­ing that you have down­loaded 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 appli­ca­tion

$server­path ='http://www.esynaps.com/WebServices/DailyDiblert.asmx';

// Define method name­space

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

// Cre­ate client object

$client = new soapclient($serverpath);

// Cre­ate client object

$soa­paction = 'http://tempuri.org/DailyDilbertImagePath';

// Make a SOAP request

$img­Path = $client->call('GetBriefings',$param,

$namespace,$soapaction);

// Catch errors, or out­put error info

if (isset($fault))

{

// Fault is ini­tial­ized. Some­thing went wrong

echo 'Error: ' . $fault;

}

else if ($img­Path == –1)

{

// Error encoun­tered

echo 'No image found yet.';

}

else

{

// Oth­er­wise out­put the result

echo '<p><img src="' . $img­Path . '" alt="Daily Dil­bert" /></p>';

}

// Kill object

unset($client);

?>

 

Click here to see today's Daily Dil­bert comic (on our main page)

Other use­ful resources

11 comments
  1. Senen Botello says: Apr 30, 20042:53 am

    Exce­lent short example

  2. Danny says: Jan 07, 20052:48 pm

    Thats pretty cool, can you post the server side code, I'm very inter­ested to see how that works as well. Thanks.

  3. sniptools says: Jan 08, 20052:21 am

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

  4. Daniele says: Apr 04, 20055:29 pm

    Shanx, this is not server side code, this is client side. We're talk­ing about web ser­vices, not about what php is :-)

  5. Matt says: Apr 08, 200511:13 pm

    IF you'll notice, the server-side (SOAP server) is a .NET web ser­vice run­ning on a totally dif­fer­ent server. Chances are that they aren't going to give you their code. This PHP just calls that service.

  6. makes says: Apr 28, 20058:12 pm

    Tried the code, but get this error:
    Parse error: syn­tax error, unex­pected T_STRING in c:\wamp\www\soap\dilbert.php on line 13

    which is:
    $name­space="http://tempuri.org/DailyDilbertImagePath";;

    Any sug­ges­tions?
    Thanks.

  7. sniptools says: Apr 30, 200510:32 am

    You seem to have two semi-colons to end that state­ment. Try remov­ing it.

  8. Roberto Andrade says: May 12, 20055:52 am

    I just get:

    Daily Dil­bert

    I mean:

    <p><img src="" alt="Daily Dil­bert" /></p>

    on Fedora Linux.

    Any sug­es­tion?

    TIA
    Roberto

  9. Rajesh says: Jul 26, 20058:33 pm

    Hi

    I copied the code given above and pasted in my own cre­ated file called dilbert.php. Copied the nusoap class from the given path. but when i try to excute the script it shows noth­ing rather than a blank page with­out any error message.

    Please help me to sort it out.
    Thanks

  10. Geoff says: Mar 09, 20066:04 am

    Roberto, I get the same thing. if I do a print_r on $img­Path, I get "
    Array
    (
    [fault­code] => soap:Client
    [fault­string] => System.Web.Services.Protocols.SoapException: Unable to han­dle request with­out a valid action para­me­ter. Please sup­ply 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, Http­Con­text con­text, HttpRe­quest request, HttpRe­sponse response, Boolean& abort­Pro­cess­ing)
    [detail] =>
    )
    "

  11. holepuncher says: Jun 08, 20073:12 am

    makes: Try mak­ing sure all your ' " are not spe­cial characters.

    Once I fixed that though, I got the same prob­lem as roberto.

Submit comment