SniptoolsSniptools | Design & Technology Observations

RSS

Dilbert a day with PHP, SOAP using NUSOAP

Jan 26th 2001
11 Comments

Respond
Trackback

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




This post is tagged

11 Comments

  1. Senen Botello

    Excelent short example

  2. Danny

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

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

  4. Daniele

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

  5. Matt

    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

    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. You seem to have two semi-colons to end that statement. Try removing it.

  8. Roberto Andrade

    I just get:

    Daily Dilbert

    I mean:

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

    on Fedora Linux.

    Any sugestion?

    TIA
    Roberto

  9. Rajesh

    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

    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

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

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

Incoming Links