Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • Magento V 1.6
  • Magento SOAP V2
  • WS-I Compliance (ie System/Configuration/Services/Magento Core API/WS-I Compliance is set to Yes)
  • Content type fix: Content Type Error Consuming Magento 1.5 Webservices from .Net
  • VS 2010
  • .Net 3.5

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

like image 356
mas Avatar asked Nov 03 '11 14:11

mas


1 Answers

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.

like image 116
iamkrillin Avatar answered Sep 30 '22 18:09

iamkrillin