2011-11-03 36 views
12

我想一個C#應用程序連接到Magento的1.6(通過Magento的SOAP V2):C#SOAP - 錯誤使用下面的代碼反序列化的回覆郵件的正文(Magento的API)

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> 

我ü唱:

任何想法如何,我可以科幻x(或調試)這個問題?

+0

愚蠢的問題:您是否使用了正確的SOAP/API的用戶名/ passwor d? (與管理控制檯登錄不同) –

回答

0

我很喜歡不熟悉的與整個「Web服務== Soap == WS- *」開發堆棧,但我知道Magento 1.6爲它的API引入了一個名爲「WS-I Compliance」的東西。您需要使用V2 Soap URL,並且還需要設置爲

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

爲「是」(在Magento System的管理員中)。這將告訴Magento使用soap_wsi處理程序而不是soap_v2處理程序。你可以看到,在

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

不知道這是否會幫助你處理Magento的SOAP請求控制器,但你包括

  • WS-I符合

和詞匹配所以有一個外部機會會有幫助。

+0

是的這就是我的意思是「我正在使用WS-I合規性」,我將編輯該問題以使其更清晰。此外,爲了確認 - 在使用WS-I時,您是否知道我是否應該使用Web服務:http://www.website.com/api/v2_soap?wsdl或者我應該使用其他服務? – mas

+0

啊,道歉,我雖然「WS-I Compliance」意味着C#方面的一些東西。是的,「api/v2_soap」是觸發Magento的soap_wsi處理程序的正確URL。 –

+0

謝謝。來自Magento的響應似乎沒有問題(它正在發送會話ID)。無論如何,你知道我在哪裏可以找到Visual Studio期望的結果嗎? – mas

22

這實際上很容易修復。打開您正在使用連接到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> 

記下綁定配置和綁定類型。在上面的基本HTTP綁定/ 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生成的代理,它給讀者配額,如沒有足夠大到默認值保存所有的數據。簡單地增加它們就像我在上面的例子中所做的那樣。

+1

我知道這是現在很老,但如果你在代碼中這樣做,你可以添加'bind.ReaderQuotas = Xml.XmlDictionaryReaderQuotas.Max;' –

+2

@PaulFarry你的權利,唯一的問題是你必須記得做它每次創建一個客戶端。在配置中做它使得它'全球'來說 – iamkrillin

+0

我也不得不這樣做 basicHttpBinding –

0

我試過所有上述的答案,但它並沒有解決我的問題,在我的具體情況下,我發現它是數據成員DateTime類型創建問題。 以前我是設定數據作爲

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

然後將其改變爲
2015-03-29T09:30:47 - >工作

一些日期怎麼不能夠序列