I finally found the reason for the problem and the solution:
The problem: SOAPv2 with WS-I does not use the single_data
and multi_data
attributes. Therefore the check in /app/code/core/Mage/Catalog/Model/Product/Api/V2.php
in _prepareDataForSave
fails.
The method _prepareDataForSave
checks for single_data
and multi_data
which are both not part of the SOAP-Call, according to the WSDL for SOAPv2 with WS-I.
SOAPv2 (WSDL) - catalogProductCreateEntity:
<element name="additional_attributes" type="typens:catalogProductAdditionalAttributesEntity" minOccurs="0"/>
SOAPv2 with WS-I (WSDL) - catalogProductCreateEntity:
<xsd:element name="additional_attributes" type="typens:associativeArray" minOccurs="0">
</xsd:element>
associativeArray is of type associativeEntity which includes key/value pairs. In SOAPv2 withous WS-I, the catalogProductAdditionalAttributesEntity
is used (which consists of single_data and/or multi_data values which again include key/value pairs).
This is the SOAPv2 WS-I part of the WSDL which describes the format of additional_attributes:
<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>
The check for additional_attributes /app/code/core/Mage/Catalog/Model/Product/Api/V2.php
worded fine, but the check for single_data or multi_data always returned false.
The solution:
I found another SOAP Problem here where the last answer was the solution to my problem: https://stackoverflow.com/a/9502311/865443).
So I put this block in my code in _prepareDataForSave
which solved the problem of setting the additional_attributes values:
if (gettype($productData->additional_attributes) == 'array') {
foreach ($productData->additional_attributes as $k => $v) {
$_attrCode = $k;
$productData->$_attrCode = $v;
}
}
I hope this helps someone else encountering the same problem. I would also appreciate an explanation for this differencde between SOAPv2 and SOAPv2 WS-I and/or other ways which solved this problem.
The problem you're experiencing is that .NET/C# is having trouble parsing the content type Magento is sending along with it's response. SOAP is notoriously finicky about receiving just the right stuff in just the right format. Couple that with PHP's rather poor implementation of the protocol and you're in for a lot of fun.
I'm looking at a Magento 1.9 for the following information:
After some digging I found that the header for the SOAP calls are set in app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php
on line 52.
51. ->clearHeaders()
52. ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
53. ->setBod...
Note that that Content-Type header matches your text/xml; charset=utf-8
desired charset. Adjusting line 52 to:
52. ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset, true)
tells Magento to force overwriting that header if it's already set.
Make sure to make a copy of the file with it's full path to the app/code/local/Mage/...
to avoid overwriting core files. You'll thank me when you want to upgrade Magento at some point.
Also, make sure to look carefully, there's two setHeader() calls in that file.
And finally, there's also a WS-I compliant SOAP adapter available, the same fix applies to that file. You can find it in app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
.
Best Answer
John suggested good thread which mention nice extension N98_ApiLogger. It logs API requests and responses. All logs are displayed in admin backend.
I found another way. by adding mage log to Soap.php. I was looking for Wsi v2 so my file is app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
around line 102 just after closing try block, add
Thanks