C# SOAP - Error in deserializing body of reply message (Magento API)
Asked Answered
F

4

13

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?

Fresno answered 3/11, 2011 at 14:50 Comment(1)
Silly question: Are you using the correct SOAP/API username/password? (different from the admin console login)Matchbox
S
22

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.

Sulfide answered 28/11, 2011 at 4:23 Comment(4)
I know this is quite old now, but if you are doing this in code you can add bind.ReaderQuotas = Xml.XmlDictionaryReaderQuotas.Max;Docilu
@PaulFarry your right, only problem there is you have to remember to do it everytime you create a client. Doing it in the config makes it 'global' to to saySulfide
I also had to do <readerQuotas maxStringContentLength="bignumber"> under basicHttpBindingEffort
I don't know what it all means, but it fixed my issue. Thanks!Publication
L
3

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

Lamoreaux answered 21/7, 2015 at 8:58 Comment(1)
How do you fix this in the client side application when receiving the XML from a web service?Chloramphenicol
M
1

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.

Matchbox answered 3/11, 2011 at 17:53 Comment(4)
Yes that's what I meant with "I'm using WS-I Compliance", I'll edit the question to make it clearer. Moreover, just to confirm - when using WS-I, do you know if I should be using the web service at: website.com/api/v2_soap?wsdl or should I use something else?Fresno
Ah, apologies, I though "WS-I Compliance" meant something on the C# side. Yes, "api/v2_soap" is the correct URL to trigger Magento's soap_wsi handler.Matchbox
Thanks. Response from Magento seems to be fine (it is sending the session ID). By any chance, do you know where I can find what Visual Studio is expecting as a result?Fresno
@Fresno No idea, not a C# developer. Good luckMatchbox
T
0

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

Tabitha answered 29/5, 2020 at 3:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.