Note: This question was originally part of Magento SOAP API V2 with C#: Issue with Stores that Require HTTP Authentication but I have moved a part of it here as a new question, as one part was already answered on that post.
ISSUE:
I have built a tool to import sales orders from customer stores (magento) for integration into our legacy order processing system. I have five stores to import from. Three work fine. Two of them have the following problem:
-
The following Exception is thrown upon executing the
salesOrderList()call:A first chance exception of type ‘System.InvalidOperationException’ occurred in System.Xml.dll
There is an error in XML document (2, 372).
The login succeeds, I am able to enumerate attribute values, etc.
But I am unable to run thesalesOrderList()function with any
filter (andnulltoo). It would be great if someone has experience
with this and can point me in the right direction, please.
Update: The invoking call is as follows:
salesOrderEntity[] soe = mservice.salesOrderList(mlogin, objSalesOrderFilterSet);
The Exception is, There is an error in XML document (2, 372).
The InnerException is, The specified type was not recognized: name=’salesOrderListEntity’, namespace=’urn:Magento’, at .
Fiddler showed the following requested and returned for the salesOrderList() call:
Requested:
POST /api/v2_soap/index HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.239)
VsDebuggerCausalityData: uIDPoz6RG9JzwkdBniF95/gqmAcAAAAAhgJHnbvB1UOTE1y4R1Iq5VGLcSLUxTNDg57BO/4OizgACQAA
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:Mage_Api_Model_Server_V2_HandlerAction"
Host: www.contoso.com
Content-Length: 1753
Expect: 100-continue
Returned:
POST http://www.contoso.com/api/v2_soap/index HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.239)
VsDebuggerCausalityData: uIDPoz6RG9JzwkdBniF95/gqmAcAAAAAhgJHnbvB1UOTE1y4R1Iq5VGLcSLUxTNDg57BO/4OizgACQAA
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:Mage_Api_Model_Server_V2_HandlerAction"
Host: www.contoso.com
Content-Length: 1753
Expect: 100-continue
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:Magento" xmlns:types="urn:Magento/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><tns:salesOrderList><sessionId xsi:type="xsd:string">2f9c5bdc898fd92c1f61981147ee5495</sessionId><filters href="#id1" /></tns:salesOrderList><tns:filters id="id1" xsi:type="tns:filters"><complex_filter href="#id2" /></tns:filters><soapenc:Array id="id2" soapenc:arrayType="tns:complexFilter[3]"><Item href="#id3" /><Item href="#id4" /><Item href="#id5" /></soapenc:Array><tns:complexFilter id="id3" xsi:type="tns:complexFilter"><key xsi:type="xsd:string">created_at</key><value href="#id6" /></tns:complexFilter><tns:complexFilter id="id4" xsi:type="tns:complexFilter"><key xsi:type="xsd:string">created_at</key><value href="#id7" /></tns:complexFilter><tns:complexFilter id="id5" xsi:type="tns:complexFilter"><key xsi:type="xsd:string">status</key><value href="#id8" /></tns:complexFilter><tns:associativeEntity id="id6" xsi:type="tns:associativeEntity"><key xsi:type="xsd:string">from</key><value xsi:type="xsd:string">2011-12-28 00:00:00</value></tns:associativeEntity><tns:associativeEntity id="id7" xsi:type="tns:associativeEntity"><key xsi:type="xsd:string">to</key><value xsi:type="xsd:string">2011-12-28 23:59:59</value></tns:associativeEntity><tns:associativeEntity id="id8" xsi:type="tns:associativeEntity"><key xsi:type="xsd:string">in</key><value xsi:type="xsd:string">processing</value></tns:associativeEntity></soap:Body></soap:Envelope>
HTTP/1.1 200 OK
Date: Thu, 05 Jan 2012 12:11:19 GMT
Server: Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/1.0.0-fips mod_bwlimited/1.4 mod_fcgid/2.3.6
X-Powered-By: PHP/5.3.6
Content-Length: 6302
Content-Type: text/xml; charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:salesOrderListResponse><result SOAP-ENC:arrayType="ns1:salesOrderListEntity[1]" xsi:type="ns1:salesOrderListEntityArray"><item xsi:type="ns1:salesOrderListEntity"><increment_id xsi:type="xsd:string">100001306</increment_id><store_id
...<more data>...
xsi:type="xsd:string">John</firstname><lastname xsi:type="xsd:string">Doe</lastname><telephone xsi:type="xsd:string">999-999-9999 ext. 3333</telephone><postcode xsi:type="xsd:string">11111</postcode></item></result></ns1:salesOrderListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
OKay, here goes. The service reference in the original program was created by pointing to a
wsdladdress under one of our Magento Go stores. The program allowed dynamically changing the shop to work with, and so the URL was changed to the relevant shop URL appended with/api/v2_soap/indexat runtime.As explained in the question, the sales order import worked for some sites and failed for others. After some pretty good advice by balexandre, we used fiddler and some on-the-spot code as needed and figured out the issue.
The Problem Was: The service call
salesOrderList()returns salesOrderEntity[] for Magento Go shops andsalesOrderListEntity[]for 1.5.x shops. As the proxy was created using a Magento Go reference, the latter type was “unexpected” for the program, thereby causing theExceptionThere is an error in XML document (2, 372) with theinnerExceptionThe specified type was not recognized: name=’salesOrderListEntity’, namespace=’urn:Magento’. All the other methods that we had invoked from the web service worked though. But without sales order listing, they weren’t much useful on their own.An Intermediate Workaround Was: To tweak the
wsdlfile andreference.csto declare ‘salesOrderListEntityand to create an overloaded version ofsalesOrderListEntity()`. But this workaround created more problems than it solved.The Final Solution Is: Create two different proxies by pointing to Magento Go and Magento 1.5.x. After switching to the actual shop URLs at runtime, use the proxy relevant for the current shop. Same calls and flow, except that the first proxy knows that it will receive
salesOrderEntity[]for asalesOrderList()call and the second proxy knows that it will receivesalesOrderListEntity[].This works without issues and we have imported a few hundred sales orders as I write this. And it seems to work well for 1.6.1 shops as well. But I shall let you know if (God forbid) there be any issues on that front.
On a concluding note, my sincere thanks to balexandre for all the help extended.