I am trying to set up a SOAP client on one server to communicate with Magento on a test server. Both servers have PHP's SOAP extension installed, configured and show up in phpinfo().

Tried turning off caching, using the v2 and v1 APIs and everything else I could think of. Regardless, I keep getting the same problems.

Either its:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode>SOAP-ENV:Server</faultcode>
                <faultstring>
                    Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: 
                    Couldn't find <definitions> in 'http://myserver.com/api/v2_soap?wsdl=1' 
                    in dispatch.php:39 

                    Stack trace: #0 dispatch.php(39): 
                    SoapClient->SoapClient('http://myserver.com/...', Array) #1 {main} thrown
                </faultstring>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

or sometimes another error SOAP doesn't allow DTD....

I'm now using just the plain Magento example code from here, instead of running anything significant, until I can figure out what's going on with this.

If I do file_get_contents to the service URL, I get:

<?xml version="1.0" encoding="UTF-8"?>
<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/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Magento" targetNamespace="urn:Magento">
    <types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
        <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
        <complexType name="associativeEntity">
        <all>
            <element name="key" type="xsd:string"/>
            <element name="value" type="xsd:string"/>
        </all>
        </complexType>
        .
        .
        .
</definitions>

So seems like it should not have trouble parsing this.. idk.

up vote 16 down vote accepted

Apparently I fell prey to a common Magento pitfall, so I'm posting the answer in case anyone else is searching this particular error. Basically, the error was coming from the Magento installation I was trying to call via the SOAP API.

Initially I thought the error was generated by the client being unable to locate this definitions result, however the real situation is as follows.

  • The Magento installation which is acting as a SOAP server makes some SOAP client calls to itself.
  • These calls lookup the same domain you are accessing in your client script, but originate from the sever on which that domain is hosted and loopback to said server.
  • Therefor, you need to check your host file, usually at /etc/hosts for Linux distros and try to append Your.IP.Address.Here Your.Magento.Domain (i,e 70.0.0.2 magentohost.com)
  • Ensure that iptables allows loopback connections, especially if you try to run localhost instead of your external IP; but most likely you'll need to use the external IP address.

That's it; once I edited the file: /etc/hosts and added this one line, everything worked fine.

If anyone has clearer insight or a generally better answer - please feel free to post and it will most likely be accepted over this answer.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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