我的 .wsdl 文件正在下载但无法打开,解析 WSDL 错误

发布于 2025-01-13 23:18:16 字数 4023 浏览 0 评论 0原文

我正在尝试读取 wsdl 文件,但出现错误:

未捕获的肥皂故障 异常:[WSDL] SOAP-错误:正在解析 WSDL:无法从以下位置加载 'http://localhost:8081/soap/news.wsdl':无法加载外部 实体“http://localhost:8081/soap/news.wsdl” /var/www/app/soap/soap-client.php:22 堆栈跟踪:#0 /var/www/app/soap/soap-client.php(22): SoapClient->SoapClient('http://localhos...', Array) #1 {main} 抛出 在 /var/www/app/soap/soap-client.php 第 22 行

这是我在 server-client.php 中的代码:

$url = "http://localhost:8081/soap/news.wsdl";
$client = new SoapClient($url);

阅读论坛后,尝试添加扩展名“openssl”,但错误仍然存​​在。当我尝试打开 http://localhost:8081/soap/news.wsdl 时,该文件未打开,而是自动下载。我尝试在 nginx cfg: 中拼写:

location ~ \.wsdl$ {
        root /var/www/app;
        default_type application/xml;
        }

但这也没有帮助。

我认为问题出在 nginx 配置上。我的配置:

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;
    } 
}

我的 WSDL 文件“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>

顺便说一下,我尝试打开另一个人的 .wsdl 文件。他很好。请帮我解决这个问题,我已经伤透了:(

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 :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖凝香 2025-01-20 23:18:16

我遇到了同样的问题,我花了几天时间才弄清楚如何解决它。

我的代码在 DEV 中运行良好,但在 PROD 中则不行。

问题是由于 libxml 版本:

  • 在开发中: libxml 版本 2.7.6
  • 在产品中: libxml 版本 2.9.1

您可以检查您的版本回显:phpinfo ();

要解决该问题,请尝试:

在加载外部 xml 之前添加:libxml_disable_entity_loader(false);

此函数禁用/启用加载外部的功能实体。从 libxml 2.9.0 开始,它似乎默认被禁用

https://www.php.net/manual/en/function.libxml-disable-entity-loader.php

祝你好运!

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:

  • In dev: libxml Version 2.7.6
  • In prod: libxml Version 2.9.1

( 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文