1

I am not much familiar with webservices or SOAP/REST, but i have been trying to figure out why xml file wont load with the following url (which i found in error log),

example.com/index.php/api/v2_soap

which says

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>
SOAP-ERROR: Parsing WSDL: Couldn't load from 'example.com/index.php/api/v2_soap/index/?wsdl=1' : failed to load external entity "example.com/index.php/api/v2_soap/index/?wsdl=1"
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

and after searching forms and magento SE, i found to test my url like the following, and it worked

 example.com/index.php/api/v2_soap?wsdl=1

i am confused, as of why the first url will throw error, and second url will load. I also see in the error and second url the placement of /index right before ?wsdl=1 whereas on the second url, it doesn't have.

What is the best place to learn all about SOAP and API related to magento?

  • 1
    I think there are 2 Problems. Magento try to connect via soap to /index.php/api/v2_soap?wsdl=1 and the Soap-Client can't resolve your domain. So, if you add 127.0.0.1 yourdomain.com to the server /etc/hosts it will solve the first issue. If you call now the URL you get the Error Invalid XML and thats in my opinion the second Problem. – Pawel Aug 19 '16 at 12:38
3

The Magento 1 soap server attempts to address itself by domain name. If you look in the apache access logs you should be seeing errors when attempting to test the soap connection like this.

This can be seen in Mage_Api_Model_Server_Adapter_Soap::_instantiateServer where it has a bit of code like:

try {
    $this->_soap = new Zend_Soap_Server($this->getWsdlUrl(array("wsdl" => 1)),
        array('encoding' => $apiConfigCharset));
} catch (SoapFault $e) {

This means there are a few different things that can trip up the instantiation of the soap API, all heavily dependent on your server setup.

The server should be able to access itself by domain name

As Alex has said, this one should be easy enough to check out, simply try and curl http://example.com the server from itself. If this throws an error force the server in the hosts file by adding something like 127.0.0.1 example.com.

If there are multiple servers they should each only talk to themselves (Discovered here)

If you have multiple servers shared between a load balancer, make sure that the hosts files are updated so that each server only talks to itself. Crosstalk seemed to cause problems in my experience.

Custom admin panel url (Discovered here)

I've seen magento websites which use a custom url for the admin panel, like http://secretadmin.example.com/admin. This secretadmin domain would then be blocked off and restricted at an apache/nginx level. This is a pretty solid approach for defending the admin panel, but plays hell with the soap client.

When the soap server tries to instantiate itself by domain name it gets the URL from Mage_Api_Model_Server_Adapter_Soap::getWsdlUrl which runs in the admin scope, if the admin domain is locked down or inaccessible from other web servers this can cause connectivity issues.

This can be easily fixed by rewriting Mage_Api_Model_Server_Adapter_Soap and forcing a frontend store scope on the getWsdlUrl function.

Further issues?

Any further errors that pop up will likely be any custom PHP or XML code in place for custom API methods, rather than soap server instantiation/connectivity issues.

  • where can i find PHP error generated by magento on a server? – Nofel Aug 23 '16 at 13:19
  • magento specific errors can be found in /path/to/magento/var/log/system.log and /path/to/magento/var/log/exception.log. A typical apache location would be /var/log/apache/error.log – Luke Rodgers Aug 23 '16 at 14:26
  • what is the difference between system and exception when i do curl it shows me a correct xml format, which means my server config in etc is bad? i do have a different badend link instead of /admin, might be that? – Nofel Aug 23 '16 at 14:28
  • Where are you doing the curl request from? The different backend link only matters if the bit before the .com is different. If its just a secret admin url like .com/secretadmin then it should be fine. – Luke Rodgers Aug 24 '16 at 13:41
  • after adding the ip next to the domain.com it giving me invalid xml error – Nofel Sep 2 '16 at 10:54
1

The first URL is an API endpoint, you should talk "SOAP" to it. In the background, Magento tries to connect to itself to load the WSDL. This for some reason does not work. Probably due to some misconfiguration of the server. To troubleshoot, see if you can open the URL

yourserver.com/index.php/api/v2_soap/index/?wsdl=1

From within your own server (for example using curl example.com/index.php/api/v2_soap/index/?wsdl=1) on the shell or in a test php file file_get_contents('example.com/index.php/api/v2_soap/index/?wsdl=1');

The second URL just prints the WSDL, so it works.

  • If i do curl, i can load it – Nofel Aug 23 '16 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.