WSDL文件在浏览器中加载,但不在代码中加载

时间:2013-11-27 05:08:24

标签: java php magento soap wsdl

我们正在尝试连接到我们的magento soap / wsdl后端,我们可以在浏览器中加载XML文件时加载它。

http://<url>/index.php/api/v2_soap?wsdl

但是当我们通过wsimport(java)生成的客户端或通过非常简单的PHP代码来实现它时:

<?php
  $proxy = new SoapClient('http://<url>/index.php/api/v2_soap?wsdl');
  $sessionId = $proxy->login('test', 'test');

  var_dump($proxy->call($sessionId, 'customer.list'));
?>

我们收到以下错误:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: 
Parsing WSDL: Couldn't load from 'http://<url>/index.php/api/v2_soap?wsdl' : 
Start tag expected, 
'<' not found in /home/test/public_html/test_api.php:3 
Stack trace: 
#0 /home/test/public_html/test_api.php(3): 
SoapClient->SoapClient('http://<url>...') 
#1 {main} thrown in 
/home/test/public_html/test_api.php on line 3

如果我们在浏览器中打开与上述相同但没有?wsdl的内容:

http://<url>/index.php/api/v2_soap

它也会导致相同的解析错误。

用户名和api密钥正确,用户所在的组具有完全权限。

更新 我们还尝试使用SoapUI给出了相同的错误。

这是我们从浏览器访问网址时得到的结果:

<wsdl:definitions xmlns:typens="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Magento" targetNamespace="urn:Magento">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<xsd:complexType name="associativeEntity">
<xsd:sequence>
<xsd:element name="key" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="associativeArray">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="complexObjectArray" type="typens:associativeEntity"/>
</xsd:sequence>
</xsd:complexType>

4 个答案:

答案 0 :(得分:1)

我们只花了两天时间。为我们解决的问题是打开位于Web Services Configuration下的System -> Cache Management缓存。

所以你应该离开这个......

a picture of the configuration having the web services configuration cache turned off

到此......

a picture of the configuration having the web services configuration cache turned on

答案 1 :(得分:0)

如果即使在浏览器中打开解析错误仍然存​​在,那么我认为SOAP服务器中必定存在一些错误(可能是语法错误)

答案 2 :(得分:0)

<?php
    $soap_client = new SoapClient("http://<url>/index.php/api/v2_soap?wsdl");
    $info = new StdClass();
    $info->key = "test";
    $info->value = "test";
    $param = array($info);
    $result = $soap_client->__soapCall('customer.list',$param);
    var_dump($result);
?>

试试这个代码...... 从xml我看到您的wsdl似乎不需要对连接进行任何身份验证。

希望您能找到一些帮助代码......

答案 3 :(得分:0)

我遇到了同样的问题,这个技巧为我做了这个工作:

我所做的只是:

更改:

http://<url>/index.php/api/v2_soap?wsdl

http://<url>/index.php/api/v2_soap.wsdl

注意问号“?”在第一个链接中替换为句点“。”在最后一个“wsdl”之前的第二个链接中。