I spent pretty much
all of yesterday trying in vain to write a soap client to connect to a web service provided by our new partner in Green Bay, WI.
After about 6 solid hours of getting the same error, a great programmer and acquaintence of mine,
Jared Smith gave me a quick tip on how to fix it.
Before I get to the fix, let me say that first, I decided to use the internal SOAP extension native to PHP 5, and therefore read a fairly large amount of documentation, trying to get it to connect.
The error I was getting was this:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://services.somewhere.com/orderdog/order.asmx' : Premature end of data in tag html line 3 in /var/www/somewhere/main/grab_product.php:3 Stack trace: #0 /var/www/somewhere/main/grab_product.php(3): SoapClient->SoapClient('http://services...') #1 {main} thrown in /var/www/somewhere/main/grab_product.php on line 3
The more I googled, the more frustrated I became because nothing out there seemed to give me any direction as to what this error meant - and what's worse is that PHP's documentation (comments included) seemed to be just as helpless.
I was using one line of code, and I had previously verified that PHP was indeed compiled with soap support.
Here was the one line of code:
$webservice = new SoapClient("http://services.somewhere.com/orderdog/order.asmx");
Yup... Not even that worked.
So, I went to my faithful
UPHPU IRC group and posed the question. Jared Smith (jsmith) was quick to, not only answer my question, but at the same time, quick to write a 100-line script detailing pretty much everything that I needed to know to build a basic web service client (SOAP) app in PHP. There's open source for ya. What a great group of people.
So,
the fix to the problem noted above was summed up in 5 more characters of code, which EASILY could have been included in the documentation for SOAP with PHP:
$webservice = new SoapClient("http://services.somewhere.com/orderdog/order.asmx?WSDL");
If you don't look closely, you won't even notice the difference - and I honestly have no idea why the extra characters are necessary - or even if they are universally necessary. All I know is that they made my app connect successfully.
*sigh*
I have no idea why some of the littlest things in code which make it impossible for the code to function at all, aren't documented anywhere.
But, anyway, that's how you solve the problem - or at least one way to solve it - and I know that if it wasn't for Jared, I would still be banging my head on this problem today.
Open Source FTW.