I am having a problem with incomplete XML SOAP responses.
the setting was like this:
- Linux server
- Magento CE 1.5.1.0
- Using SOAP v2 with WS-I Compliance Enabled
- Call of sales_order.info
Even if you are using a different version of Magento and a different SOAP call, you may encounter a similar error like me. The problem was that the HTTP Content-Length header was not calculated correctly for responses> 8000 bytes .
How to check if this error affects :
- Make a call that provides a short answer (for example, "catalog_category.info" with only one store view and with only a few attributes). If XML is complete, check to see if the response is & lt; = 8000 bytes.
- Copy the file app / code / core / Mage / Api / Model / Server / Wsi / Adapter / Soap.php to your application / code / local folder and edit the run () method. If you use the wsdl parameter in the SOAP URL, edit the first part of the if structure, otherwise edit the else part.
Since the second way is a more accurate way to do this, I will go with it.
- Open the file and search for the method -> setBody (). As you can see, some search / replace magic happens.
Write the result of the search / replace operations into a variable and write it down for further study. The code might look like this:
public function run() { $apiConfigCharset = Mage::getStoreConfig("api/config/charset"); if ($this->getController()->getRequest()->getParam('wsdl') !== null) { } else { try { $this->_instantiateServer(); $content = preg_replace( '/(\>\<)/i', ">\n<", str_replace( '<soap:operation soapAction=""></soap:operation>', "<soap:operation soapAction=\"\" />\n", str_replace( '<soap:body use="literal"></soap:body>', "<soap:body use=\"literal\" />\n", preg_replace( '/<\?xml version="([^\"]+)"([^\>]+)>/i', '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>', $this->_soap->handle() ) ) ) ); Mage::log($content, null, 'soap.log'); $this->getController()->getResponse() ->clearHeaders() ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset) ->setBody($content); } catch( Zend_Soap_Server_Exception $e ) { $this->fault( $e->getCode(), $e->getMessage() ); } catch( Exception $e ) { $this->fault( $e->getCode(), $e->getMessage() ); } } }
Make a SOAP API call and open the var / log / soap.log file in the Magento folder. If the XML is completed in the log file but not in your response, then the Content-Length header is the problem.
How to fix Content-Length header
Remain in your copy of Mage_Api_Model_Server_Wsi_Adapter_Soap and add one line to the code we just changed:
public function run() { $apiConfigCharset = Mage::getStoreConfig("api/config/charset"); if ($this->getController()->getRequest()->getParam('wsdl') !== null) { } else { try { $this->_instantiateServer(); $content = preg_replace( '/(\>\<)/i', ">\n<", str_replace( '<soap:operation soapAction=""></soap:operation>', "<soap:operation soapAction=\"\" />\n", str_replace( '<soap:body use="literal"></soap:body>', "<soap:body use=\"literal\" />\n", preg_replace( '/<\?xml version="([^\"]+)"([^\>]+)>/i', '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>', $this->_soap->handle() ) ) ) ); Mage::log($content, null, 'soap.log'); $this->getController()->getResponse() ->clearHeaders() ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset) ->setHeader('Content-Length',strlen($content), true) ->setBody($content); } catch( Zend_Soap_Server_Exception $e ) { $this->fault( $e->getCode(), $e->getMessage() ); } catch( Exception $e ) { $this->fault( $e->getCode(), $e->getMessage() ); } } }
Pay attention to the line:
->setHeader('Content-Length',strlen($content), true)
We calculate and set the Content-Length header. The third parameter, true, is important because it tells the structure to overwrite the existing Content-Length header.
- If this works, remove the call to Mage :: log () and rewrite the code to use in your own extension.
If you ask why , this problem arises, I canβt say for sure, because I did not look for the error to the end.
From what I saw, everything is fine as long as the XML response is & lt; = 8000 bytes. If the response is longer than 8000 bytes and the XML consists of x lines, the response is truncated with x characters. This seems to be a problem with different carriage return codes and / or coding problems that lead to an incorrect calculation of the length of the response content.
source share