使用 C# 从 Magento 导入销售订单(salesOrderList 函数):“XML 文档中存在错误 (2, 372)”

发布于 2024-12-25 04:14:02 字数 5269 浏览 1 评论 0原文

注意:这个问题最初是 使用 C# 的 Magento SOAP API V2:需要 HTTP 身份验证的商店存在问题,但我已将其中一部分作为新问题移至此处,因为其中一部分已得到解答帖子。

问题: 我构建了一个工具来从客户商店 (magento) 导入销售订单,以便集成到我们的旧订单处理系统中。我有五家商店可供进口。三个工作正常。其中两个存在以下问题:

  • 执行 salesOrderList() 调用时抛出以下异常:

    <块引用>

    System.Xml.dll 中第一次出现“System.InvalidOperationException”类型的异常

    XML 文档中存在错误 (2, 372)。

    登录成功,可以枚举属性值等。 但我无法使用任何命令运行 salesOrderList() 函数 过滤器(还有null)。如果有人有经验那就太好了 有了这个,请给我指出正确的方向。


更新:调用如下:

salesOrderEntity[] soe = mservice.salesOrderList(mlogin, objSalesOrderFilterSet);

异常是,XML 文档中存在错误 (2, 372)。< br> InnerException 是,无法识别指定的类型:name='salesOrderListEntity'、namespace='urn:Magento', at 。

Fiddler 显示以下请求和为 salesOrderList() 调用返回:
请求:

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

返回:

    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>

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 the salesOrderList() function with any
    filter (and null too). 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愿与i 2025-01-01 04:14:02

这有一个简单的修复方法,尽管可能需要一些时间并且您需要更改一些代码。

问题: 如果不低于 1.6.0,您将无法使用 Magento WSDL 地址,因为它包含仅在 1.6 中修复的奇怪错误,请阅读 发行说明每个版本了解更多信息

解决方案:从项目中删除所有服务引用并使用svcutil.exe 实用程序指向来自最新 Magento 的 wsdl 地址(即使您只是为此安装最新版本,迄今为止的最新稳定版本是 1.6 .1).

然后将生成的项目添加到您的 web/win 项目并使用其中的服务,并交换 Client 对象中的最终 url,例如:

MyNameSpace.MagentoSoapClient ws = new MyNameSpace.MagentoSoapClient();
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://domain.com/api/v2_soap");

尝试一下。

This has an easy fix, though it might take some time and you need to change some code.

The problem: You can't use the Magento WSDL address if not less than 1.6.0, as it contains weird bugs that are fixed only with 1.6, read the release notes of each version for more information

The Solution: Remove all Service References from your project and create a proxy using the svcutil.exe utility pointing to a wsdl address that is from the most recent Magento (even if you install the latest version just for this, the latest stable to this date is 1.6.1).

Then add that generated project to your web/win project and use the service from it, and swap the final url in the Client object, for example:

MyNameSpace.MagentoSoapClient ws = new MyNameSpace.MagentoSoapClient();
ws.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://domain.com/api/v2_soap");

give that a try.

烦人精 2025-01-01 04:14:02

好的,开始了。原始程序中的服务引用是通过指向我们的 Magento Go 商店之一下的 wsdl 地址创建的。该程序允许动态更改要使用的商店,因此 URL 在运行时更改为附加了 /api/v2_soap/index 的相关商店 URL。

正如问题中所解释的,销售订单导入对某些网站有效,而对其他网站则失败。在 balexandre 提供了一些很好的建议后,我们根据需要使用了 fiddler 和一些现场代码并解决了问题。

问题是: 服务调用 salesOrderList() 返回 Magento Go 商店的 salesOrderEntity[] 和 salesOrderListEntity[]对于 1.5.x 商店。由于代理是使用 Magento Go 引用创建的,后一种类型对于程序来说是“意外的”,从而导致 Exception XML 文档中存在错误 (2, 372) 带有 innerException 无法识别指定的类型:name='salesOrderListEntity',namespace='urn:Magento'。不过,我们从 Web 服务调用的所有其他方法都有效。但如果没有销售订单清单,它们本身并没有多大用处。

中间解决方法是:调整 wsdl 文件和 reference.cs 以声明“salesOrderListEntity并创建 的重载版本” /code>salesOrderListEntity()`。但这种解决方法产生的问题多于它解决的问题。

最终解决方案是:通过指向 Magento Go 和 Magento 1.5.x 创建两个不同的代理。在运行时切换到实际商店 URL 后,使用与当前商店相关的代理。相同的调用和流程,只不过第一个代理知道它将接收 salesOrderList() 调用的 salesOrderEntity[],而第二个代理知道它将接收 salesOrderListEntity[]

这可以正常工作,并且在我撰写本文时我们已经导入了数百个销售订单。它似乎也适用于 1.6.1 商店。但如果(上帝禁止)这方面有任何问题,我会让你知道。

最后,我衷心感谢 balexandre 提供的所有帮助。

OKay, here goes. The service reference in the original program was created by pointing to a wsdl address 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/index at 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 and salesOrderListEntity[] 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 the Exception There is an error in XML document (2, 372) with the innerException The 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 wsdl file and reference.cs to 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 a salesOrderList() call and the second proxy knows that it will receive salesOrderListEntity[].

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文