PHP SoapClient 不加载 WSDL [英] PHP SoapClient doesn't load WSDL

查看:36
本文介绍了PHP SoapClient 不加载 WSDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 WSDL:

<wsdl:import location="http://example.lan:8082/XServizi?wsdl=Sei.wsdl";命名空间=http://esempio.it/"></wsdl:import><wsdl:binding name="XServiziServiceSoapBinding";type=ns1:Sei"><soap:binding style="document";运输=http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="HelloWorldOperation"><soap:operation soapAction="";样式=文档"/><wsdl:input name="HelloWorldOperation"><soap:body use=文字"/></wsdl:input><wsdl:output name=HelloWorldOperationResponse"><soap:body use=文字"/></wsdl:output></wsdl:操作></wsdl:binding><wsdl:service name="XServiziService"><wsdl:port binding="tns:XServiziServiceSoapBinding";名称=XServiziPort"><soap:address location="http://example.lan:8082/XServizi"/></wsdl:port></wsdl:service></wsdl:定义>

我尝试在 PHP 中使用 SoapClient 导入,但出现此错误:

<块引用>

SOAP 错误:解析 WSDL:无法从https://example.lan:8083/XServices?wsdl"加载:无法加载外部实体https://example.lan:8083/XServices?wsdl"

我还添加了登录并传入 SoapClient.我不知道为什么,对于其他 WSDL,它可以工作.

我也不能用 SoapUI 导入.我收到此错误:

<块引用>

错误加载 [http://example.lan:8082/XServices?wsdl=Sei.wsdl]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: 错误: 没有关闭标签.

我也在 SoapUI 中禁用了代理,但它不起作用.

有什么建议吗?

解决方案

根据错误信息,问题与您发布的 WSDL 文件中的 有关.您的 WSDL 由两部分组成:您正在查看的部分和可在 URL http://example.lan:8082/XServizi?wsdl=Sei.wsdl

您的错误消息显示了两种不同的内容.

一个是 https://example.lan:8083/XServices?wsdl 有问题,另一个是 http://example.lan:8082/XServices?wsdl=Sei.wsdl.我不确定您在发布此问题时如何编辑这些 URL 以保护隐私,以及为什么一个在端口 8083 上而另一个在端口 8082 上,但这个想法是 WSDL 的所有部分都需要可访问:

  • 您的工具需要可以访问主 WSDL 的 URL;
  • 主要 WSDL 导入的 URL 也需要您的工具可以访问;

只有这样,您的工具才能读取 WSDL 及其所有部分并生成 SOAP 客户端.

另请注意,某些工具会阻塞 WSDL 的导入(请参阅此处了解详情).对 PHP SoapClient 不够熟悉,但不知道这里是否是这种情况.

由于您无法控制服务,您的选择是以某种方式使这两个 XML 可用于您的工具.

首先确保 URL 可访问.

如果不是这样,那么以某种方式获取他们的内容.拥有它们后,您可以将本地 PHP 服务器中的两个 URL 的内容保存为 main.wsdl(这是您在问题中显示的 WSDL)和 second.xml(这是导入的内容).然后在您的 main.wsdl 中更改导入位置.例如,如果您将文件在本地公开为 http://localhost:80/main.wsdlhttp://localhost:80/second.xml 然后在 main.wsdl 您将导入更改为如下所示:

然后指向 SoapClient 或 SoapUI 来读取 http://localhost:80/main.wsdl.

您可以在磁盘上尝试此操作并将文件并排放置在同一文件夹中,然后将导入更改为:

然后将工具指向磁盘上的 main.wsdl 文件.我不确定这会起作用.从来没有尝试过.SoapUI 可能能够从同一文件夹中获取文件,我怀疑是 PHP SoapClient.

还可以选择下载两个 XML 文件并将它们合并为一个 WSDL 文件(基本上是手动解析导入),然后仅使用此文件作为工具.不过,您必须知道自己在做什么,才能获得有效且正确的 WSDL 文件.

或者最后,您可以要求服务提供商提供一个您可以使用的 WSDL 文件.没有必要要求他们更改当前的 WSDL,因为很可能他们也有其他客户端,并且为您修复此问题可能会破坏其他人的东西(如上面的链接中所述).

但这可能只是一个可访问性问题,因此在将它们与 SOAP 工具一起使用之前,请确保这些 URL 可从您的浏览器访问.

I have this WSDL:

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:tns="http://sei.esempio.it/" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:ns2="http://schemas.xmlsoap.org/soap/http" 
    xmlns:ns1="http://esempio.it/" name="XServiziService" 
    targetNamespace="http://sei.esempio.it/">
<wsdl:import location="http://example.lan:8082/XServizi?wsdl=Sei.wsdl" 
             namespace="http://esempio.it/"> </wsdl:import>
<wsdl:binding name="XServiziServiceSoapBinding" type="ns1:Sei">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="HelloWorldOperation">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="HelloWorldOperation">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="HelloWorldOperationResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="XServiziService">
  <wsdl:port binding="tns:XServiziServiceSoapBinding" name="XServiziPort">
    <soap:address location="http://example.lan:8082/XServizi"/>
  </wsdl:port>
</wsdl:service>
</wsdl:definitions>

I tried to import with SoapClient in PHP, but I get this error:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://example.lan:8083/XServices?wsdl' : failed to load external entity "https://example.lan:8083/XServices?wsdl"

I added also login and pass in SoapClient. I don't know why, with other WSDL, it works.

I can't import with SoapUI either. I get this error:

Error loading [http://example.lan:8082/XServices?wsdl=Sei.wsdl]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: does not close tag .

I disabled also the proxy in SoapUI, but it doesn't work.

Any suggestions?

解决方案

Based on the error messages, the problem is related to the <wsdl:import> inside the WSDL file you posted. Your WSDL is composed of two parts: the one you are diplaying and the one that can be found at the URL http://example.lan:8082/XServizi?wsdl=Sei.wsdl

Your error messages show two different things.

One has a problem with https://example.lan:8083/XServices?wsdl and the other with http://example.lan:8082/XServices?wsdl=Sei.wsdl. I'm not sure how you edited these URLs for privacy when posting this question and why one is on port 8083 and the other on port 8082, but the idea is that all parts of the WSDL need to be accessible:

  • the URL of the main WSDL needs to be accessible by your tooling;
  • the URL that the main WSDL imports also needs to be accessible by your tooling;

Only then will your tooling be able to read the WSDL and all its parts and generate a SOAP client.

Note also that some tools choke on WSDLs with imports (see here for details). Not familiar enough with PHP SoapClient though to know if that's the case here.

Since you can't control the service, your options are to somehow make both XMLs available to your tooling.

First make sure the URLs are accessible.

If that's not the case, then somehow get a hold of their content. When you have them, you could save the content of the two URLs in your local PHP server as main.wsdl (this is the WSDL you are showing in your question) and second.xml (this is what's imported). Then in your main.wsdl you change the import location. For example, if you expose the files locally as http://localhost:80/main.wsdl and http://localhost:80/second.xml then in main.wsdl you change the import to look like this:

<wsdl:import location="http://localhost:80/second.xml" namespace="http://esempio.it/"></wsdl:import>

then point the SoapClient or SoapUI to read http://localhost:80/main.wsdl instead.

You could try this on disk and place the files one next to each other in the same folder, then change the import to:

<wsdl:import location="second.xml" namespace="http://esempio.it/"></wsdl:import>

then point the tools to the main.wsdl file on disk. I'm not sure this will work though. Have never tried it. SoapUI might be able to fetch the files from the same folder, the PHP SoapClient I doubt so.

There is also the option of downloading both XML files and combine them into just one WSDL file (basically resolving the import manually) then use just this file for your tooling. You will have to know what you are doing though, in order to obtain a valid and correct WSDL file.

Or finally, you could ask the service provider to give you just one WSDL file you can use instead. There is no point of asking them to change the current WSDL because most likely they have other clients too and fixing this for you might break stuff for somebody else (as mentioned in the link above).

But this is probably just an accessibility issue, so make sure those URLs are accessible from your browser before using them with SOAP tools.

这篇关于PHP SoapClient 不加载 WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆