0

I have a problem with the allposters.com SOAP (http://webservice.allposters.com/). I am trying to fetch some product information via (a slightly modified) nuSOAP PHP library (http://sourceforge.net/projects/nusoap/) on a PHP 5.3 installation.

My request is (all the characters are exactly like here, they are not converted to entities):

POST /ProductInformationService.asmx HTTP/1.0
Host: webservice.allposters.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductByProductNumberInformation"
Content-Length: 570

<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <GetProductByProductNumberInformation xmlns="http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService">
            <APCSearchXml>
                <WebSiteID>1234567890</WebSiteID>
                <SearchTerm>1234567</SearchTerm>
                <LanguageID>1</LanguageID>
                <CurrencyCode>USD</CurrencyCode>
            </APCSearchXml>
        </GetProductByProductNumberInformation>
    </soap:Body>
</soap:Envelope>

And I get the error

Length cannot be less than zero. Parameter name: length

in this specific response

HTTP/1.1 200 OK
Connection: keep-alive
Date: Tue, 08 Jan 2013 18:46:59 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 821

<APC_Search_Results>
   <StatusCode>1</StatusCode>
   <Search_Error>
       <ErrorNumber>1</ErrorNumber>
       <ErrorDescription>Length cannot be less than zero. Parameter name: length</ErrorDescription>
   </Search_Error>
</APC_Search_Results>

The communication seems to be working fine; if I remove the "WebSiteID" element from my previous request, I would get

Index was out of range. Must be non-negative and less than the size of the collection.

Unfortunatelly, from the few examples I found on the web and from a 7-pages document on their website with a sample in Visual Basic (this is the only documentation I was able to find), I really can't figure out what I am missing, and that .NET error doesn't tell me something I can use.

Did someone experienced similar problems with the allposters.com affiliate webservice and have some advice?

halfer
  • 19,824
  • 17
  • 99
  • 186
Corneliu
  • 1,110
  • 1
  • 10
  • 16
  • 1
    Where are you sending a `length` parameter? If you're not, should you be? – Madbreaks Jan 08 '13 at 19:49
  • Sounds like you need to be passing a length parameter – SSH This Jan 08 '13 at 20:03
  • Thank you for the suggestions, however the "Length cannot be less than zero. Parameter name: length" is not due to a missing "length" parameter in my request (I've already tried adding it), but looks like an ASP error from their server when my request is processed, probably on a string substract operation or something, where the length parameter comes to be negative. I can't figure out what, from my request, triggers this problem on their server, because the documentation is pretty poor. – Corneliu Jan 08 '13 at 20:21
  • @Corneliu - glad you found a solution. Would you copy out your solution into an answer and revert the edit in the question? Since we have an API here, it is best for question fields to just contain questions, and answer fields to just contain answers. You don't have to accept your own answer, of course. – halfer Jan 08 '13 at 21:17

2 Answers2

2

You are using the Soap service in the wrong way.

If you look at the example on the page for the call "GetProductByProductNumberInformation" on http://webservice.allposters.com/ProductInformationService.asmx?op=GetProductByProductNumberInformation there is only a placeholder "string" mentioned, but you are sending a complete set of XML. This is probably wrong.

I don't know why you think you can send more than a string like the XML you did, but I found out that this service actually expects you to send your XML wrapped inside a CDATA so that it is just a string - the server then unpacks the string and does another XML parsing.

This implementation method is completely bullshit, because it circumvents the point of having a Soap Service with a WSDL description of what kind of parameters the service allows and expects - but you are most unlikely to change that.

So you have to make NuSoap to wrap your XML string inside CDATA tags, otherwise it won't work at all, I think.

Sven
  • 69,403
  • 10
  • 107
  • 109
0

The OP offered the following solution in a question edit, so I am moving to an answer proper:

<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <GetProductByProductNumberInformation xmlns="http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService">
            <APCSearchXml>
                <![CDATA[ 
                  <APC_Search_Query>
                        <WebSiteID>1234567890</WebSiteID>                        
                            <SearchText>123456</SearchText>
                        <LanguageID>1</LanguageID>
                        <CurrencyCode>USD</CurrencyCode>
                  </APC_Search_Query>
                ]]>
            </APCSearchXml>
        </GetProductByProductNumberInformation>
    </soap:Body>
</soap:Envelope>
halfer
  • 19,824
  • 17
  • 99
  • 186