PEAR::SOAP SOAP_Fault not working or not documented
| From: | (Jonathan Schilling) | Date: | Fri, 07 Mar 2003 22:00:00 +0000 |
| Subject: | PEAR::SOAP SOAP_Fault not working or not documented | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-455@lists.php.net to get a copy of this message | ||
I'm using PEAR::SOAP 0.7.1 for a web service, and the SOAP_Fault
mechanism is not working for me. Clients are interpreting the
fault return as a regular, string-typed result, whose value is
all the returning SOAP XML, rather than as an actual fault.
PEAR::SOAP doesn't have any real doc on how SOAP faults are
supposed to be processed, nor does the examples/ directory
help much. Anybody have any working examples of fault handling?
Attached are small test cases showing my problem, with clients
in both PEAR::SOAP and in Perl.
Thanks for any assistance,
Jonathan Schilling Caldera/SCO jls@sco.com
Service is hello-service.php:
<?php
require_once('SOAP/Server.php');
$server = new SOAP_Server();
$server->_auto_translation = true;
class SOAP_Hello_Service {
var $dispatch_map = array();
function SOAP_Hello_Service() {
$this->dispatch_map['helloWorld'] =
array('in' => array('inmessage' => 'string'),
'out' => array('outmessage' => 'string') );
}
function helloWorld($inmessage) {
if ($inmessage == 'foo') {
$fault = new SOAP_Fault('Do not pass me foo!', '12345');
return $fault->message();
} else {
return "Hello $inmessage";
}
}
}
$soaphelloserver = new SOAP_Hello_Service();
$server->addObjectMap($soaphelloserver, 'urn:SOAP_Hello_Service');
$server->service($HTTP_RAW_POST_DATA);
?>
Client is this SOAP::Lite Perl script hello2-php.pl:
#! /usr/bin/perl
use lib '/home/jls/.cpan/build/SOAP-Lite-0.52/lib';
use SOAP::Lite;
my $str = shift;
my $soap = SOAP::Lite
-> uri('urn:SOAP_Hello_Service')
-> proxy('http://mymachine.caldera.com/jls/hello-service.php');
my $result = $soap->helloWorld($str);
unless ($result->fault) {
print "Result string is: ", $result->result(), "\n";
} else {
print join ', ',
$result->faultcode,
$result->faultstring, "\n";
}
Running it for a "good" parameter:
$ perl hello2-php.pl abc
Result string is: Hello abc
Now running it for a "bad" parameter:
$ perl hello2-php.pl foo
Result string is: <?xml version="1.0"
encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode
xsi:type="xsd:QName">SOAP-ENV:12345</faultcode>
<faultstring xsi:type="xsd:string">Do not pass me
foo!</faultstring>
<faultactor xsi:type="xsd:anyURI"></faultactor>
<detail
xsi:type="xsd:string"></detail></SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The same thing happens with a Java client using Apache Axis, and
indeed with a PEAR::SOAP client ./hello2-client.php:
#! /usr/bin/php -q
<?php
include("SOAP/Client.php");
$str = $argv[1];
$soapclient = new SOAP_Client("http://mymachine.caldera.com/jls/hello-service.php");
$options = array('namespace' => 'urn:SOAP_Hello_Service', 'trace'
=> 1);
$ret = $soapclient->call("helloWorld",
array("inmessage"=>"$str"), $options);
if (is_object($ret) && get_class($ret) == 'soap_fault') {
printf("Error! ");
print_r($ret); print "\n";
} else {
printf("Return string is %s \n", $ret);
}
?>
$ ./hello2-client.php abc
Return string is Hello abc
$ ./hello2-client.php foo
Return string is <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode xsi:type="xsd:QName">SOAP-ENV:12345</faultcode>
<faultstring xsi:type="xsd:string">Do not pass me foo!</faultstring>
<faultactor xsi:type="xsd:anyURI"></faultactor>
<detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>