Magento的SOAP API V2的响应内容长度不正确 [英] Magento Soap API V2 Response Content Length Incorrect

查看:302
本文介绍了Magento的SOAP API V2的响应内容长度不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力为我们的Magento安装与第三方库存管理应用(基于.NET)连接。但同步不工作,第三方告诉我,SOAP API是返回一个空的响应。

We are trying to connect our magento installation with a third party stock management app(built on .net). But the sync is not working, the third party tells me that the soap api is returning an empty response.

我一直在拉我听得出,因为每当我在PHP中做任何事情的API工作正常。此外库存更新工作正常,但为了检索/发票信息没有(当然它实际上偶尔1%的时间)

I have been pulling my hear out, because whenever I make anything in PHP the API works fine. In addition inventory updating works fine, but retrieving order/invoice information does not (well it actually does occasionally 1% of the time)

随着我们认为,这必须是一个网络问题,但很多搜索和添加法师::日志()到核心API文件后,我可以看到连接正在发生,进一步响应对象是间歇性通过Magento的创建。

With the intermittent nature we felt that it must be a network issue, but after lots of searching and adding mage::log() into the core api files I can see that the connection is happening and further more the response object is being created by Magento.

所以,我作为扣除的东西是不正确的SOAP API(我用的第2版)

So my deduction as that something was not right with the SOAP API (I am using version 2)

我已经安装的soapUI和设置我们的集成,它正确地接收到来自WSDL文件的方法,但是当我尝试访问登录方法,我得到一个空的响应,甚至当我把不正确的登录信息为空

I have installed soapUI and setup our integration, it correctly receives the methods from the WSDL file but when I try to access the "login" method I get an empty response, even when I put in the incorrect login details it is empty.

的soapUI输出以下错误:

soapUI outputs the following error:

错误:时出错[内容长度定界消息体(预期的premature结束:267;收:266],看到错误日志的详细信息

因此​​,它好像有一个与HTTP标头的问题,有些功能都能够返回一个响应(当然不登录哈希它仅仅是无效的,但至少它是一个响应)。从Java和.NET的我(非常有限)的理解,他们对这些东西比PHP这将说明为什么PHP集成就没有问题,更严格。

So it seems as though there is an issue with the http headers, some functions are able to return a response (of course without the login hash it is just invalid, but at least it is a response). From my (exceedingly limited) understanding of java and .net, they are much stricter on these things than php which would indicate why a php integration would have no issues.

谁能告诉我,为什么会出现这种错误,以及如何解决它?

Can anyone advise me why this error would occur and how to fix it?

推荐答案

我要假设你使用的是WS-I标准的SOAP API V2作为我有这个相同的问题;如果没有,则这可能仍然适用。我从来没有能够连接到V2 API,而它是WS-I标准,这是我发现了这个错误。

I'm going to assume you are using the WS-I compliant SOAP API v2 as I had this exact same issue; if not, then this still might apply. I was never able to connect to the v2 API without it being WS-I compliant, which is how I found this bug.

如果你有看应用程序/ code /核心/法师/原料药/型号/服务器/ WSI /适配器/ Soap.php 文件,你会看到在基本上分成两部分的公共运行功能 - 1为实际的SOAP响应WSDL定义响应和1。

If you have a look at the app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php file you will see in the public run function that is essentially split into two parts - 1 for the WSDL definition response and 1 for the actual SOAP response.

在SOAP响应有一点串替换回事,替换<肥皂:操作的soapAction =>< / SOAP:操作> <肥皂:操作的soapAction =/> 等。这显然​​是导致与内容长度计算的问题 - 这也是发生在WSDL定义响应,但它似乎并没有被引起的问题。

In the SOAP response there is a bit of string replacing going on, substituting <soap:operation soapAction=""></soap:operation> for <soap:operation soapAction="" /> and so on. This is evidently causing an issue with the content-length calculation - this is also occurring in the WSDL definition response, but it doesn't seem to be causing an issue.

我能够通过更换与下面的code中的尝试大括号中的code成功连接到SOAP API。基本上,我结束了清除头和重新计算的内容长度 的字符串替换发生了:

I was able to successfully connect to the SOAP API by replacing the code between the try curly brackets with the code below. Basically, I ended up clearing the headers and recalculating the content-length AFTER the string replacement had taken place:

            $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()
                                        )
                                )
                        )
                    );

            $this->getController()->getResponse()
                      ->clearHeaders()
                      ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset)
                      ->setHeader('Content-Length',strlen($content))
                      ->setBody($content);

希望这有助于

这篇关于Magento的SOAP API V2的响应内容长度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆