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.

<?php
require_once('nusoap.php');
$parameters = array(
        'APC_Search_Query' => array(
                'WebSiteID'=>"94454",
                'CategoryID'=>"999999",
                'PageNumber'=>"1",
                'ProductsPerPage'=>"15",
                'SearchText'=>"Matrix",
        )
);

$soapclient = new soapclient('http://webservice.allposters.com/ProductInformationService.asmx');
$soapclient->debug_flag = 1;
$namespace = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService/";
$soapAction = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation";

$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 AllPosters.com, 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.
Debug: http://www.oneclickdesigns.com/debug.txt

Any help would be greatly appreciated.

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

<?php
ini_set( 'include_path', '.:/usr/share/pear:/usr/bin/pear');
require_once("SOAP/Client.php");
$soapclient = new SOAP_Client('http://webservice.allposters.com/ProductInformationService.asmx');
$namespace = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService";
$soapAction = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation";
$parameters = array(
        'APCSearchXml' => array(
                'WebSiteID'=>"94454",
                'CategoryID'=>"101",
                'PageNumber'=>"1",
                'ProductsPerPage'=>"15",
                'SearchText'=>"Matrix"
        )

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

And this is returned from AllPosters:

<APC_Search_Results>
   <StatusCode>1</StatusCode>
   <Search_Error>
   <ErrorNumber>-77</ErrorNumber>
   <ErrorDescription>An error has occured. Please try again.
APCErrorCode: 73db3aea-b3c3-4152-a3b4-64ec33d9bcac.
</ErrorDescription>
</Search_Error>
</APC_Search_Results>

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 phpsoap.org 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:

Hi,

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
GW

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('http://webservice.allposters.com/ProductInformationService.asmx');
$soapclient->soap_defencoding = "UTF-8";
$soapclient->namespaces = array(
		'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
		'xsd' => 'http://www.w3.org/2001/XMLSchema',
		'soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
);
		
$namespace = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService"; 
$soapAction = "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation";

$xml = array("APCSearchXml"=>"<![CDATA[<APC_Search_Query>".
			"<WebSiteID>".$WEBSITE_ID."</WebSiteID>".
			$searchterms .
			"<ProductsPerPage>20</ProductsPerPage>".
			"<SortOrder>p</SortOrder>".
			"</APC_Search_Query>]]>"
			);

//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="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string;
	}

	// serialize headers
	if($headers){
		$headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
	}
	// serialize envelope
	return
	'<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
	'<soap:Envelope'.$ns_string.">".
	$headers.
	"<soap:Body>".
		$body.
	"</soap:Body>".
	"</soap:Envelope>";
    }

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
GW

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 . . .

Response:

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=/

<APC_Search_Results>
   <StatusCode>0</StatusCode>
   <Search_Result>
<Total_No_Of_Products>30</Total_No_Of_Products>
<No_Of_Products_In_Current_Page>1</No_Of_Products_In_Current_Page>
<Current_PageNumber>1</Current_PageNumber>
<Products>
  <ProductInformation>
    <ProductNumber>401384</ProductNumber>
    <ProductLink>http://www.allposters.com/-sp/Floral-Poetry-IV_i401384_.htm?aid=252003033</ProductLink>
    <Title>Floral Poetry IV</Title>
    <Artist>Tricia Harrison</Artist>
    <ArtistLink>http://www.allposters.com/-st/Tricia-Harrison-Posters_c36739_.htm?aid=252003033</ArtistLink>
    <ImageHeight>400</ImageHeight>
    <ImageWidth>320</ImageWidth>
    <ThumbnailHeight>115</ThumbnailHeight>
    <ThumbnailWidth>92</ThumbnailWidth>
    <ProductHeight>10</ProductHeight>
    <ProductWidth>8</ProductWidth>
    <ProductType>Art Print</ProductType>
    <Directory>BEN</Directory>
    <ThumbnailFileName>AB10648_a.jpg</ThumbnailFileName>
    <ImageFileName>AB10648.jpg</ImageFileName>
    <ThumbnailURL>http://imagecache2.allposters.com/IMAGES/BEN/AB10648_a.jpg</ThumbnailURL>
    <ImageURL>http://imagecache2.allposters.com/IMAGES/BEN/AB10648.jpg</ImageURL>
    <CanBeMounted>Y</CanBeMounted>
    <MountedLink>http://affiliates.allposters.com/link/redirect.asp?item=401384&amp;event=Mounted&amp;AID=252003033&amp;PSTID=1&amp;LTID=5&amp;lang=1</MountedLink>
    <CanBeFramed>Y</CanBeFramed>
    <FramedLink>http://affiliates.allposters.com/link/redirect.asp?item=401384&amp;event=Framed&amp;AID=252003033&amp;PSTID=1&amp;LTID=5&amp;lang=1</FramedLink>
    <CanBeQuickFramed>Y</CanBeQuickFramed>
    <ListPrice>5.0000</ListPrice>
    <OurPrice>5.9900</OurPrice>
    <Rank>11</Rank>
    <DateAdded>2003-07-24T16:37:00.0000000-07:00</DateAdded>
    <MatchCount>30</MatchCount>
  </ProductInformation>
</Products>
</Search_Result> 
</APC_Search_Results>3

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: http://www.php.net/manual/en/class.soapclient.php