Error WSDL: SOAP-ERROR: Parsing WSDL: Couldn't load from
Asked Answered
H

4

17

My problem is very common. I read almost all topics on stackoverflow about this issue, but still can not do thing work. My code is :

ini_set("soap.wsdl_cache", "0");
ini_set("soap.wsdl_cache_enabled", "0");
$proxy = new SoapClient('http://Myhostname/api/soap?wsdl');

I had this error :

Error WSDL: SOAP-ERROR: Parsing WSDL: Couldn't load from 
'http://Myhostname/api/soap?wsdl' : failed to load external entity 
"http://Myhostname/api/soap?wsdl"

In the browser the URL

http://Myhostname/api/soap?wsdl

works great (returns an xml response)

I try this code to see if PHP can reach this URL :

if (file_get_contents('http://Myhostname/api/soap?wsdl') === false) {
    echo "ERROR: file_get_contents <br/>";
}

It displays me my error "ERROR: file_get_contents", so it does not work. On the forums I saw that to solve this problem I must add hostname into OS "hosts" file. So I did it. In my hosts file I added this line 127.0.0.1 Myhostname

But it still does not work. Then I changed URL in my code to

http://localhost/Myhostname/api/soap?wsdl

but it does not work either.

I tried another solution I found on the internet. For some people it worked. In my URL I changed '?' character to '.'. So my new URL became

http://localhost/Myhostname/api/soap.wsdl

but it does not work either.

I saw official SOAP doc! And tried to create SoapClient object in different way (with options like 'proxy_host' and 'proxy_port'). But this did not help me.

It's my second day I try to solve this problem, but I can not. I am doing my internship, I do not have a lot of experience, so maybe I did not try solutions I found correctly. Maybe someone can help. I would be very pleased.

Head answered 12/4, 2013 at 2:20 Comment(6)
I think that in some cases, you can't file_get_contents() to your hostname from the server itself behind that hostname. Have you tried running this code from a local environment?Reticular
Have you tried http://127.0.0.1/Myhostname/api/soap?wsdl?Metalline
Actually it was some kind of server configuration problem. My supervisor fixed it. Thank you anyway guys.Head
Did the supervisor tell you what the config problem was? Could come in handy for all others looking for it ;)Masochism
I am trying to solve the same problem for one whole day and still not able to solve it. Would you please share what the config problem was?Lipography
I am sorry, but it was a long time ago and I do not work with him already.Head
S
3

Few steps to check

Have a ping to Myhostname. It would give the ip. Use ip instead and see

Check if the services are enabled S0AP, php_openssl, openssl, curl

Hope you would get it :)

Salbu answered 22/4, 2013 at 9:53 Comment(0)
R
2

I have the similar problem, I solve it uncommenting -MultiViews from .htaccess file, and later from Apache configuration of local website.

My working Apache configuration is:

<Directory /var/www/>
        Options Indexes FollowSymLinks -MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

You can try also url:

http://localhost/Myhostname/api.php?type=soap&wsdl

if you use community edition.

Ramsdell answered 22/4, 2013 at 9:14 Comment(0)
G
1

instead of $proxy = new SoapClient('http://Myhostname/api/soap?wsdl');
try $proxy = new SoapClient(WSDLFILENAME);
where WSDLFILENAME is the OS name of the WSDL file. This has the additional benefit of making one client-server roundtrip less.

Ginsberg answered 28/4, 2013 at 17:41 Comment(0)
G
0

I tried the SOAP Web Services on my local host and it was working fine. The reason why the Magento was not able to give a response to the request was because it was not able to verify SSL Certificates enabled on the site.

The way I resolved it was to allow self signed SSL verification:

$opts = [
    'http' =>
     [
         'header' => "Authorization: Bearer ".$token
        ],
'ssl' => [
    'allow_self_signed' => true , 
    'verify_peer' => false, 
    'verify_peer_name' => false]
];
$context = stream_context_create($opts);

I hope it helps. ;)

Garbage answered 24/10, 2018 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.