PHP SoapClient can't load WSDL file, but it can load others - php

I know there are countless threads on this, but nothing suggested has worked for me.
When trying to create a new SoapClient, I get the error:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't load from 'https://m2mconnect.ee.co.uk/orange-soap/services/MessageServiceByCountry?wsdl' :
failed to load external entity "https://m2mconnect.ee.co.uk/orange-soap/services/MessageServiceByCountry?wsdl"
The WSDL file is: https://m2mconnect.ee.co.uk/orange-soap/services/MessageServiceByCountry?wsdl.
I thought it might be a https issue, but I've successfully loaded other wsdl clients. It seems to just be this EE one that won't work, and it's getting very frustrating!
I'm running my application on a vagrant instance with php5.5, on a mac os x host. I've tried running it on mac os x and I get the same problem.
I've also tried setting the 'ssl_method' option for SoapClient, but that has no effect.
I've tried to curl/wget the url and it gets an SSL error, whereas it completes the handshake with something like https://paypal.com
Does anyone have any ideas what could be causing this?
Update:
I ran this on the vagrant box: curl -v -SSLv3 https://m2mconnect.ee.co.uk/orange-soap/services/MessageServiceByCountry?wsdl and it connected successfully, however, creating a SoapClient with the option ssl_method set to SOAP_SSL_METHOD_SSLv3 doesn't work

I ended up forking BeSimpleSoapClient which wrapped SoapClient and uses Curl to get the SoapService. I modified their Curl class to allow setting of curl ssl version: https://github.com/robcaw/BeSimpleSoapClient

I was able to access the WSDL location right now with a browser.
So the only answer remaining is: IF you get SSL errors when trying to download the WSDL with curl or wget, then it is safe to assume PHP has the same error - and the solution would be to fix them - and as a first step, mentioning your findings in your question.
As it looks right now, PHP is not to blame, everything you did should work - the only thing missing is the network connection to fetch the WSDL.

Related

PHP SoapClient - "failed to load external entity" although WSDL is valid and accessable in browser/curl

This issue has been plaguing me for a few hours. I can access the wsdl perfectly fine in my browser and using curl, however PHP SoapClient returns an error when using the following code:
$ps_client = new SoapClient("https://ppds.hitpromo.net/productData");
Here is the error it's returning:
Fatal error: Uncaught SoapFault exception:
[WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://ppds.hitpromo.net/productData' :
failed to load external entity "https://ppds.hitpromo.net/productData"
I tried a variety of solutions including setting various options when calling the constructor but nothing seems to be working.
This ended up not being the actual fix, it was happening because SSL was not enabled in php. I fixed it by commenting out this line in php.ini:
extension=openssl
In my case, I was able to construct the SoapClient using the http uri, however it threw an error when calling functions because SSL was not enabled.
OLD ANSWER:
Turns out this was a really simple fix. I'm not sure why, but changing it from https to http fixed everything:
$ps_client = new SoapClient("http://ppds.hitpromo.net/productData");
Really frustrating issue, because I've been playing around with this same WSDL on java and did not run into this while using ksoap. I wanted to post it because I'm sure someone might have the same problem some day.
This error occurs because your site is on a host whose firewall prevents swaps.
Contact your host company to add the IP of the swap site to the firewall whitelist.
You do not need to delete ssl or coding to ignore it.

PHP Make SOAP Client Request Returns 500 Internal Server Error

I'm using PHP to make SOAP request. I do have information of the web service from the third party. Basically what they have give me:
The full URI request ( http://xx.xx.xx.xx:xxxxxx/some/services/BasicDo )
Username & Password
I am pretty new however I could understand a bit how PHP SOAP things work. However in the example I found the URL called is something like http://xx.xx.xx.xx/services/myservice?wsdl which is not really same with what I have with me. Additional question here is what should I ask them? Perhaps what is the name of wsdl file?
Also so far I have this code with me:
try{
$client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));
}
catch(SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
But from the console, I received status 500 Internal Server Error. I don't know how this can be, I am expecting something from the catch block. Somebody please clarify me this. Thank you in advance.
Unfortunately, it seems like no matter what you try (e.g. passing array('exceptions' => 0), SoapClient() will throw an uncatchable E_ERROR on network connection issues. This bug is still present as high up as PHP 5.5.4 (REF).
Summary:
Test script:
$client=#new SoapClient('garbage',array('exceptions'=>FALSE));
echo 'OK';
Expected result: We should see "OK",
Actual result:
If we use register_shutdown_function to display the contents of error_get_last(), we get:
Array
(
[type] => 1
[message] => SOAP-ERROR: Parsing WSDL: Couldn't load from 'garbage' : failed
to load external entity "garbage"
)
To explain why you suddenly get this error without changing anything on your system, and to explain why SoapClient works on your local machine and not on your production system, it is most likely a firewall issue.
Here is what another person reported that solved his problem:
I solved my problem. It was actually an issue with my firewall. The
firewall was dropping packets sent via PHP, but via curl or wget were
not being dropped. I added a rule for all traffic from that server and
increased the packet drop length and everything is working great now!
Advice:
My best advice at this time to write some code in the same PHP file that checks if the SOAP service url resolves and loads properly before calling the SoapClient.
Add these codes at head of the file to see where the error happen
ini_set('display_errors','1');
error_reporting(E_ALL);
I am not sure what the issue may be but I did the following to debug this issue when I encountered it
$client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));
Things you can do:
Create a PHP file. Name it anything. Write the following code there:
ini_set('display_errors','On');
$client = new SoapClient("http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl", array('login'=>"myusername",'password'=> "mypwd"));
var_dump($client);
exit;
Run the file.
Chances are this will show you the required exception.
In my case, Our server used a proxy which I had not passed in the parameters due to which I was getting the issue.
Let us know how it goes.
Thanks
First you need to make sure you have access to the SOAP server.
From the machine that is running your php script try to access the wsdl file and check if it is valid.
you can for example use wget http://xx.xx.xx.xx:xxxxx/some/services/BasicDo?wsdl then open the saved file and see what you are getting. Is it a valid wsdl?
Once you have sorted out our access, then you need to read the documentation here and here. You may need to authenticate differently or pass other options.
As for why the catch block is not picking up your exception, you are only catching SoapFault. The 500 internal server error can be caused by anything.
I really appreciate all of the answers given. I am actually working with another party which I don't have any access on the remote side. My job is to make SOAP request to the server. However it turned out that there is NO web service available for me. So I ended up using cURL to send raw POST of SOAP request. :-)

Http request failed after site migration - server issue

So I have a website built in php and it was working perfectly on one server, I then moved the website to a server I have on Digital Ocean and am running into several errors, they seem to be based around http request failures while using the imagick library...
I was hoping to not to have to start debugging this from a code point of view as it was already working perfectly and would prefer to change server settings.
Fatal error: Uncaught exception 'ImagickException' with message 'Imagick::__construct(): HTTP request failed! HTTP/1.1 404 Not Found .
I cannot figure out what differences there, on both server allow_url_fopen is set to on.
The php version is different, 5.520 on the original server, 5.5.9 on the new server.
The versions of imagick are the same. I am also getting some other errors using the mpdf library but I will try deal with these later (Im hoping if I can resolved the first ones these ones will also get resolved).
My question is , is there possibly any other setting on the server I should be looking out for that may be causing these php errors?
EDIT:
Just to add more information, i can get rid of some of the errors by changing the file path https://www.example.com/myimage.jpg to /var/www/example/myimage.jpg . This solves some of the errors but I would rather get the root of the issue thats causing it not to work in the first place, because I feel that its the same problem thats causing other errors.
The error code says it: 404, file not found. You are probably using the wrong URL.
Are you able to fetch https://www.example.com/myimage.jpg using a webbrowser?
On several popular linux distros, /var/www/example/myimage.jpg would be served at https://www.example.com/example/myimage.jpg instead of https://www.example.com/myimage.jpg with the default configuration.
[edit]
It just came to my attention that the URL is HTTPS, there is a possibility that the script is rejecting the server certificate. Try with regular HTTP - no point in using SSL if the file is on the same machine.

Guzzle / curl can't resolve host

I'm trying to run both my API and my client in the same Vagrant VM. In the client I'd like to use Guzzle. When I try to set up a simple test, I get the following error from curl:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message '[curl] (#6) See http://curl.haxx.se/libcurl/c/libcurl-errors.html for an explanation of cURL errors [url]
When I use a Github url instead, it all works fine. One thing I'm sure of, is that there is no typo in my url.
I have both client and API pointing to the ip-address of my VM, and both run fine separately.
I also ran into a topic on which it was suggested to use a cacert.pem certificate in php.ini, which I have tried, but it didn't work.
Any that knows how to solve this?
Stupid of me. I had to place 127.0.0.1 api.dev in the hosts file on my VM.
The error number 6 (CURLE_COULDNT_RESOLVE_HOST) means that libcurl failed to resolve a host name to an IP address.

PHP SoapClient times out

I'm trying to call a Soap Client for testing purposes from the same server that I'm running the service on. My WSDL is at: http://www.installittoday.com/api/server.php?wsdl I'm trying to load it simply with:
$client = new SoapClient('http://www.installittoday.com/api/server.php?wsdl');
but I get back the error:
Warning: SoapClient::SoapClient(http://www.installittoday.com/api/server.php?wsdl) [soapclient.soapclient]: failed to open stream: Connection timed out in /home/installi/public_html/api/client.php on line 4
Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "http://www.installittoday.com/api/server.php?wsdl" in /home/installi/public_html/api/client.php on line 4
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.installittoday.com/api/server.php?wsdl' : failed to load external entity "http://www.installittoday.com/api/server.php?wsdl" in /home/installi/public_html/api/client.php:4 Stack trace: #0 /home/installi/public_html/api/client.php(4): SoapClient->SoapClient('http://www.inst...') #1 {main} thrown in /home/installi/public_html/api/client.php on line 4
Yet I can set up the client just fine from another site of mine. Is this a firewall issue or what?
Make sure these extensions are enabled in your php.ini
extension=php_curl.dll
extension=php_openssl.dll
extension=php_soap.dll
Also loading from here fine.
Try connecting to it from the site you want the client on with a web browser, or if its a remote machine with no proxy set up use curl:
curl http://www.installittoday.com/api/server.php?wsdl
That will tell you if you can even get a connection to that site via the machine.
You could also try multiple connects, or increasing default_socket_timeout if your machines connection speed is limited/congested.
What ports are you trying to connect over?
For anyone coming across this error. Try disabling the WSDL cache, either from your php.ini or a parameter in your SOAP call.
The problem is, PHP by default caches the WSDL file in the temp folder. After the file is first cached, PHP keeps on using this file. It is only refreshed after 24 hours (the default ttl for the cache).
So if you change your WSDL file, PHP will pickup the old one, resulting in an error like the OP. Matt, your problem was solved by using referencing a file that is never cached.
The reason it is cached by default because your server has to request the file and then parse it, which takes a bit of fetching and processing.
You have two options, either amend the relevant variable in your php.ini or send a param along with your SOAP call.
For example:
$client = new SoapClient($webservice, array('classmap' => $soap_class_map, 'cache_wsdl' => WSDL_CACHE_NONE));
Hope this helps.
OP again here.
A little more context: I'm hosting the service (obviously) on installittoday.com. I'm also trying to run a client from the same place just for testing purposes. I can connect to the service from literally every other site I've tried perfectly fine, and I've successfully opened a few WSDLs with the Client hosted on installittoday. It seems the site can't connect to itself for some reason.
I sincerely doubt it's a congested line issue.
Now that I've gotten this far I realize this problem probably extends beyond SOAP to some kind of Apache configuration issue, unless there's a port thing that I'm missing. I haven't set up any ports differently, is there one I should make sure I have open for SOAP?
I solved this problem by saving the dynamically generated nusoap WSDL as a standalone file and all seems to be working just fine. I have no idea why this would be the case.
I'm planning to move it to PHP5 anyway, I was just using nuSoap to generate the WSDL.

Categories