Reputation: 31
I'm trying to read a wsdl file, I get an error:
Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost:8081/soap/news.wsdl' : failed to load external entity "http://localhost:8081/soap/news.wsdl" in /var/www/app/soap/soap-client.php:22 Stack trace: #0 /var/www/app/soap/soap-client.php(22): SoapClient->SoapClient('http://localhos...', Array) #1 {main} thrown in /var/www/app/soap/soap-client.php on line 22
Here is my code in server-client.php:
$url = "http://localhost:8081/soap/news.wsdl";
$client = new SoapClient($url);
After reading the forums, tried adding the extension "openssl", but the error remains. When I try to open http://localhost:8081/soap/news.wsdl , the file is not opened, but downloaded automatically. I tried spelling in nginx cfg:
location ~ \.wsdl$ {
root /var/www/app;
default_type application/xml;
}
But that didn't help either.
I think the problem is in the nginx config. My config:
server {
listen 80;
index index.php;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/app;
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ \.wsdl$ {
root /var/www/app;
default_type application/xml;
}
}
My WSDL file "news.wsdl" :
<?xml version='1.0' encoding='UTF-8' ?>
<definitions name='News'
targetNamespace='http://localhost:8081/news'
xmlns:tns='http://localhost:8081/news'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='getNewsByIdRequest'>
<part name='id' type='xsd:integer' /> </message> <message name='getNewsByIdResponse'>
<part name='item' type='xsd:base64Binary' /> </message>
<message name='getNewsCountResponse'>
<part name='count' type='xsd:integer' /> </message>
<message name='getNewsCountByCatRequest'>
<part name='cat_id' type='xsd:integer' /> </message> <message name='getNewsCountByCatResponse'>
<part name='count' type='xsd:integer' /> </message>
<portType name='NewsPortType'>
<operation name='getNewsById'>
<input message='tns:getNewsByIdRequest' />
<output message='tns:getNewsByIdResponse' />
</operation>
<operation name='getNewsCount'>
<output message='tns:getNewsCountResponse' />
</operation>
<operation name='getNewsCountByCat'>
<input message='tns:getNewsCountByCatRequest' />
<output message='tns:getNewsCountByCatResponse' />
</operation> </portType>
<binding name='NewsBinding' type='tns:NewsPortType'>
<soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
<operation name='getNewsById' />
<operation name='getNewsCount' />
<operation name='getNewsCountByCat' /> </binding>
<service name='NewsService'>
<port name='NewsPort' binding='NewsBinding'>
<soap:address location='http://localhost:8081/soap/soap-server.php' />
</port>
</service>
</definitions>
By the way, I tried opening another person's .wsdl file. He was fine. Please help me with this problem, I've already broken my head :(
Upvotes: 3
Views: 424
Reputation: 299
I had the same problem and i took few days to figure out how to fix it.
My code works fine in DEV but not in PROD.
The problem was because of libxml Version:
( You can check your version echoing: phpinfo(); )
To resolve the problem try to:
Add this: libxml_disable_entity_loader(false); before loading your external xml
This function disable/enable the ability to load external entities. And it seems to be disabled by default since libxml 2.9.0
https://www.php.net/manual/en/function.libxml-disable-entity-loader.php
Good luck!
Upvotes: 0