Sniptools » Tutorials

Dilbert a day with PHP, SOAP using NUSOAP

January 26, 2001 Views (15,670) /  Comments (11) /  Trackback (0) / Digg/Share


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

(229 Words | )

 
Possibly Related
Other stuff that may be of interest  
Comments
What readers have asked/said/added.

^1 Senen Botello said on April 30, 2004 2:53 AM:

Excelent short example

^2 Danny said on January 7, 2005 2:48 PM:

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

^3 Shanx said on January 8, 2005 2:21 AM:

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

^4 Daniele said on April 4, 2005 5:29 PM:

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

^5 Matt said on April 8, 2005 11:13 PM:

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 said on April 28, 2005 8:12 PM:

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 Shashank said on April 30, 2005 10:32 AM:

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

^8 Roberto Andrade said on May 12, 2005 5:52 AM:

I just get:

Daily Dilbert

I mean:

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

on Fedora Linux.

Any sugestion?

TIA
Roberto

^9 Rajesh said on July 26, 2005 8:33 PM:

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 said on March 9, 2006 6:04 AM:

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 said on June 8, 2007 3:12 AM:

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

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


 

Post a comment
Please be decent while posting comments, don't make us delete them, thanks.




Will be spam-protected.

Remember?


Comment Preview

XX said on :

 

Trackbacks
Ping @ http://sniptools.com/ping/2001-01/1. Listed below are links to weblogs that reference this article.

 

Referrals
*Some* places that viewers have come to this page from: