C# SOAP - 反序列化回复消息正文时出错(Magento API)

发布于 2024-12-13 15:16:00 字数 1201 浏览 2 评论 0原文

我正在尝试使用以下代码将 C# 应用程序连接到 Magento 1.6(通过 Magento SOAP V2):

using (Mage_Api_Model_Server_Wsi_HandlerPortTypeClient proxy = new Mage_Api_Model_Server_Wsi_HandlerPortTypeClient())
{
  string sessionId = proxy.login("XXXXXXX", "XXXXXXXXXXX");
  Console.WriteLine(sessionId);
}

并且出现以下错误:

Error in deserializing body of reply message for operation 'login'.

我使用 Fiddler 来检查传输,这就是结果:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento">
<SOAP-ENV:Body>
<ns1:loginResponseParam>
<result>fc094df96480dbbcdXXXXXXXXXXXXXXX</result>
</ns1:loginResponseParam>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我正在使用:

有什么想法可以解决(或调试)这个问题吗?

I'm trying to connect a C# app to Magento 1.6 (through Magento SOAP V2) using the following code:

using (Mage_Api_Model_Server_Wsi_HandlerPortTypeClient proxy = new Mage_Api_Model_Server_Wsi_HandlerPortTypeClient())
{
  string sessionId = proxy.login("XXXXXXX", "XXXXXXXXXXX");
  Console.WriteLine(sessionId);
}

and I get the following error:

Error in deserializing body of reply message for operation 'login'.

I used Fiddler to inspect the transfer and this is the result:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento">
<SOAP-ENV:Body>
<ns1:loginResponseParam>
<result>fc094df96480dbbcdXXXXXXXXXXXXXXX</result>
</ns1:loginResponseParam>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I'm using:

Any ideas how I can fix (or debug) this problem?

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

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

发布评论

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

评论(4

帝王念 2024-12-20 15:16:00

这实际上很容易解决。打开用于连接到 magento 的应用程序的 web.config/app.config

找到此行

<client>
      <endpoint address="http://YourWeb.com/index.php/api/v2_soap/index/" binding="basicHttpBinding" bindingConfiguration="BasicBinding" contract="Webstore.Mage_Api_Model_Server_Wsi_HandlerPortType" name="Mage_Api_Model_Server_Wsi_HandlerPort" />
</client>

记下绑定配置和绑定类型。在上面的 basicHttpBinding/BasicBinding

接下来找到以下配置部分。

<bindings>
  <basicHttpBinding>
      <binding name="BasicBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="999999" maxBufferPoolSize="999999" maxReceivedMessageSize="999999" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="999999" maxStringContentLength="999999" maxArrayLength="999999" maxBytesPerRead="999999" maxNameTableCharCount="999999" />
          <security mode="None" />
      </binding>
  </basicHttpBinding>
</bindings>

注意这里的嵌套,绑定 ->绑定类型->按名称绑定元素

当 Visual Studio 生成代理时,它为读取器配额提供的默认值不够大,无法容纳所有数据。只需将它们全部增加,就像我在上面的示例中所做的那样。

this is actually pretty easy to fix. Open the web.config/app.config for the application you are using to connect to magento

find this line

<client>
      <endpoint address="http://YourWeb.com/index.php/api/v2_soap/index/" binding="basicHttpBinding" bindingConfiguration="BasicBinding" contract="Webstore.Mage_Api_Model_Server_Wsi_HandlerPortType" name="Mage_Api_Model_Server_Wsi_HandlerPort" />
</client>

Make note of the binding configuration and binding type. In the above basicHttpBinding/BasicBinding

Next locate the following config section.

<bindings>
  <basicHttpBinding>
      <binding name="BasicBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="999999" maxBufferPoolSize="999999" maxReceivedMessageSize="999999" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="999999" maxStringContentLength="999999" maxArrayLength="999999" maxBytesPerRead="999999" maxNameTableCharCount="999999" />
          <security mode="None" />
      </binding>
  </basicHttpBinding>
</bindings>

Notice the nesting here, binding -> binding type -> binding element by name

When visual studio generates the proxy the default values that it gives for the reader quota and such are not large enough to hold all of the data. Simply increase them all like I have done in the above example.

邮友 2024-12-20 15:16:00

我尝试了上述所有答案,但它没有解决我的问题,在我的特定情况下,我发现这是具有 DateTime 类型的数据成员创建问题。
以前我将数据设置为

2015-07-21T13:55:30.5962405+05:30 -> 不工作

然后将其更改为
2015-03-29T09:30:47 --> 工作

日期无法序列化的一些原因

I tried all the above answers but it did not solves my problem, in my particular case i found out that it was data members with DateTime type creating problem.
Previously i was setting Data as

2015-07-21T13:55:30.5962405+05:30 -> Not working

then changed it to

2015-03-29T09:30:47 -> Working

Some how date was not able to serialize

此刻的回忆 2024-12-20 15:16:00

我对整个“Web Services == Soap == WS-*”开发堆栈非常不熟悉,但我知道 Magento 1.6 为其 API 引入了称为“WS-I 合规性”的东西。您需要使用 V2 Soap URL,并设置

System -> Configuration -> Magento Core Api -> General Settings -> WS-I Compliance

为“是”(在 Magento 系统的管理中)。这将告诉 Magento 使用 soap_wsi 处理程序而不是 soap_v2 处理程序。 地方看到处理 Magento Soap 请求的控制器

app/code/core/Mage/Api/controllers/V2/SoapController.php

您可以在不知道这是否对您有帮助的

  • ,但您包括了WS-I 合规性

并且单词匹配,因此它有可能会有所帮助。

I'm very unfamiliar with the whole "Web Services == Soap == WS-*" development stack, but I do know Magento 1.6 introduced something called "WS-I Compliance" for its API. You need to use the V2 Soap URL, and also set

System -> Configuration -> Magento Core Api -> General Settings -> WS-I Compliance

to "Yes" (in the Magento System's Admin). This will tell Magento to use the soap_wsi handler instead of the soap_v2 handler. You can see the controller that handles the Magento Soap requests at

app/code/core/Mage/Api/controllers/V2/SoapController.php

No idea if this will help you, but you included

  • WS-I Compliance

and the words match up so there's an outside chance it will help.

独木成林 2024-12-20 15:16:00

我更新了 Web 服务参考,它对我有用。

因为第三方服务可能会更改/更新,您也应该在您的环境中进行更新。

输入图片此处描述

I updated the Web Service reference and it works for me.

Because the third party services may changed / updated and you should be also updated in your environment.

enter image description here

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