NuSoap and AllPosters

Hello Everyone, I’m trying to reach the new AllPosters Web Services using NuSoap v1.74, but I’m running into roadblocks and none of my searching gives me any clues as to what I’m missing.

Here’s the code I’m using.

$parameters = array(
        'APC_Search_Query' => array(

$soapclient = new soapclient('');
$soapclient->debug_flag = 1;
$namespace = "";
$soapAction = "";

$response = $soapclient->call('GetProductInformation',$parameters, $namespace, $soapAction, $headers, '', '', 'literal');
if(!$err = $soapclient->getError()) {
        echo 'Result: ' . $response;
} else {
        echo 'Error: ' . $err;
echo '<h2>Request:</h2> <pre>' . htmlspecialchars($soapclient->request, ENT_QUOTES).'</pre>.';
echo '<h2>Response:</h2> <pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES).'</pre>';
echo '<h2>Debug log:</h2> <pre>' . htmlspecialchars($soapclient->debug_str, ENT_QUOTES).'</pre>';

None of the documentation or examples I have found suggest using the $soapAction variable, but I was getting errors stating the server did not understand soapAction:. Using $soapAction resolved that error, and now I do get a response from AllPosters, but I can’t seem to figure out what I’m missing. I’ve even tried hacking nusoap.php so it will generate the XML that is identical to the samples from, but no luck.

I’ve uploaded the debug info to my server. I didn’t want to post it here because it was too dang long, lol.

Any help would be greatly appreciated.

This is the code I’m using for Pear::SOAP

ini_set( 'include_path', '.:/usr/share/pear:/usr/bin/pear');
$soapclient = new SOAP_Client('');
$namespace = "";
$soapAction = "";
$parameters = array(
        'APCSearchXml' => array(

$ret = $soapclient->call('GetProductInformation', $xml, $namespace, $soapAction);

And this is returned from AllPosters:

   <ErrorDescription>An error has occured. Please try again.
APCErrorCode: 73db3aea-b3c3-4152-a3b4-64ec33d9bcac.

I tried adding echo($soapclient->wire()); and it returned:

Fatal error: Call to undefined function: wire() in /home/virtual/site3/fst/var/www/html/test2/nusoap_test.php on line 19

Not sure where I’m going wrong, at this point all I can guess is that it’s a problem on AllPosters side, still haven’t heard back from their tech support.

SOAPAction is an optional HTTP Header that is used to state what service is being called… most web services don’t require it (after all, it’s an HTTP header…).

Btw, I’ve found that as time goes on, PEAR SOAP is superior to NuSOAP, though NuSOAP is easier to get started with.

Thanks for the heads up with SOAPAction, that one had me boggled for a bit.

I’m trying to develop this as a public script, so I’m trying to stick with NuSoap as it’s much more portable than PEAR is currently. If only I could get a good response from AllPosters, I would be on a roll, lol

I’ve tried connecting with Pear::SOAP as well, and get the same error returned. Has anyone had any luck with this, or can see a flaw in my code?

Can you provide some details?

Specifically, you can do echo $client->wire in PEAR SOAP.

It should just be echo $soapclient->wire; (it’s a member attribute, not a method). Also does AllPosters have a WSDL? Might just be a malformed request parameter

Thanks for your help, after banging my head for a few days, I’ve got it worked out, the xml request had to be in this format:

"<![CDATA[<APC_Search_Query>" . $xml . "</APC_Search_Query>]]>"

I’ll actually be starting soon to try and address topics like this. SOAP interactions stretch a lot farther then just the simple documentation that might exist (i.e. the call() method definitions)… there’s complex datatypes, namespaces, interoperability, etc.

Sounds good, there are lots of examples that give you basic functionality, but not much for advanced or troubleshooting. Digging into nusoap.php itself is where I found most of the pointers. The plus side of all this, is I’ve learned quite a bit in an area that I haven’t touched.

Hiya psbrunet,

Could you post the exact code you got working here, or private message it to me or something? I’m running into the exact same errors as you were getting, but I’m just learning SOAP and it’s driving me crazy. I’m sure I’m formatting the request correctly, even with the <![CDATA]> stuff. I’m using NuSOAP… did you get your solution working with PEAR?

Curse XML! :smash:


I am having a very similar issue with using nuSOAP to connect to a :bawling: .asmx webservice. Please can you post the >final< working PHP client code?

Thanks in advance

Heya geedubb,

I got my problems sorted out, but it turns out it was an issue with the service itself. It wasn’t able to handle all the extra XML parameters that nuSOAP was adding in. I had to modify nuSOAP to remove things like the “ns1:” namespace declarations, etc. Here’s my script code:

/* Set up our SOAP stuff */			
$soapclient = new soapclient('');
$soapclient->soap_defencoding = "UTF-8";
$soapclient->namespaces = array(
		'xsi' => '',
		'xsd' => '',
		'soap' => ''
$namespace = ""; 
$soapAction = "";

$xml = array("APCSearchXml"=>"<![CDATA[<APC_Search_Query>".
			$searchterms .

//get the feed
$soapclient->charencoding = false;  //important!
$response = $soapclient->call('GetProductInformation',$xml, $namespace, $soapAction,'','','rpc','literal');

That’s more or less my exact code. The $searchterms variable I used was just some of Allposter’s XML tags, nothing special. Note that I had to turn off the “charencoding” thing that NuSOAP does, which removed some of the headers that Allposters was choking on. The other modifications I did were to nusoap.php itself. I created a separate copy for use with my allposters script because I use standard NuSOAP for other things and I didn’t want to break those. Anyway, the changes I made were all in the serializeEnvelope function, which now looks like this:

function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded'){
    // TODO: add an option to automatically run utf8_encode on $body and $headers
    // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
    // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1

	// serialize namespaces
    $ns_string = '';
	foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
		$ns_string .= " xmlns:$k=\\"$v\\"";
	if($style == 'rpc' && $use == 'encoded') {
		//$ns_string = ' SOAP-ENV:encodingStyle=""' . $ns_string;

	// serialize headers
		$headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
	// serialize envelope
	'<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".

Note the removal of the SOAP-ENV headers, and the commented out $ns_string. I’m actually sorry I didn’t use PEAR, as I ended up at the end needing the PEAR XML::Unserialize functionality anyway, and it may have been easier to deal with than NuSOAP. :rolleyes:

BTW, I emailed Allposters about the whole thing, but of course they never got back to me, which isn’t cool. It would be nice if their server was a little more robust in terms of XML handling, but of course that’s not my perogative. Anyway, good luck with your script. :smiley:

Elemental - thanks so much for your detailed answer. I now have this up and running.

All the best

Nice work! :tup: Glad I could help. It had me boggled for days :smiley:

I’m wondering if others ar noticing some strange quirks when it comes to the number of replies sent back by Allposters.

I’ve noticed that when ProductsPerPage is 9 or less, the number of results returned is correct, but when ProductsPerPage is 10 or more, it returns one less result, i.e., 10 returns 9, 20 returns 19.

I’ve also noticed weird things when the page number requested is more than the default.

Faced with a 400+ page movies request, I noticed that one page returned 19, another 6, another 8, with no apparent method to the madness.

Any similiar stories?

I’m trying to use the example code below from Elemental, and pretty much have it working. I’m a little unsure as to how to parse out the results returned though. The $response field is a string value, but when I use this code:

echo '<h2>Response:</h2> <pre>' . $soapclient->response, ENT_QUOTES .'</pre>'; 

, it displays with tags like this . . .


HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Wed, 09 Nov 2005 12:35:34 GMT
X-Powered-By: ASP.NET
Connection: keep-alive
X-AspNet-Version: 1.1.4322
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 2813
Set-Cookie: NSC_XfcTfswjdf_80=0a5183260050;path=/

    <Title>Floral Poetry IV</Title>
    <Artist>Tricia Harrison</Artist>
    <ProductType>Art Print</ProductType>

I sort of expected that $response would be an array where I could use the tag names to parse it apart.

Any suggestions?

This is 2010, 5 years after the last post. Im trying to use this script to access allposters api but no luck. Does anybody have it working in the actual version of the api by any chance? Would be lovely if someone could post a php example. Thanks

PHP now has a native SOAP client: