我试图使用以下代码将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>
我在用着:
> Magento V 1.6
> Magento SOAP V2
> WS-I合规性(即系统/配置/服务/ Magento Core API / WS-I合规性设置为是)
>内容类型修复:Content Type Error Consuming Magento 1.5 Webservices from .Net
> VS 2010
> .Net 3.5
任何想法如何修复(或调试)这个问题?
解决方法
这实际上很容易解决.打开用于连接到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生成代理时,它给予读卡器配额的默认值不足以容纳所有数据.简单地增加它们,就像我在上面的例子中所做的那样.