2011-12-06 40 views
1

我想列出我所有的產品在C#中的SOAP接口V2(.NET 4.0,VS 2010),使用WS-I兼容,Magento 1.6.1.0中的WSDL生成的SOAP接口版本。無法取得產品在Magento 1.6.1.0的SOAP API的CatalogProductList當我有超過25個產品

我可以檢索產品通常與我的代碼(附在下面),當我有少於25種產品。然而,當我有25個產品以上,我得到一個錯誤:

Unhandled Exception: System.InvalidOperationException: There is an error in XML 
document (333, 2). ---> System.Xml.XmlException: Unexpected end of file has occu 
rred. The following elements are not closed: complexObjectArray, result, ns1:cat 
alogProductListResponseParam, SOAP-ENV:Body, SOAP-ENV:Envelope. Line 333, positi 
on 2. 
at System.Xml.XmlTextReaderImpl.Throw(Exception e) 
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) 
at System.Xml.XmlTextReaderImpl.ThrowUnclosedElements() 
at System.Xml.XmlTextReaderImpl.ParseElementContent() 
at System.Xml.XmlTextReaderImpl.Read() 
at System.Xml.XmlTextReader.Read() 
at System.Xml.XmlReader.MoveToContent() 
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMagent 
oService.Read32_catalogProductEntity(Boolean isNullable, Boolean checkType) 
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMagent 
oService.Read121_Item() 
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer86.De 
serialize(XmlSerializationReader reader) 
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St 
ring encodingStyle, XmlDeserializationEvents events) 
--- End of inner exception stack trace --- 
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, St 
ring encodingStyle, XmlDeserializationEvents events) 
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie 
ntMessage message, WebResponse response, Stream responseStream, Boolean asyncCal 
l) 
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodN 
ame, Object[] parameters) 
at MagentoAPITest.mage.MagentoService.catalogProductList(String sessionId, fi 
lters filters, String store) in ....\technology\c#\MagentoAPITest 
\MagentoAPITest\Web References\mage\Reference.cs:line 1982 
at MagentoAPITest.magentoHelper.GetProducts() in ....\technolo 
gy\c#\MagentoAPITest\MagentoAPITest\magentoHelper.cs:line 62 
at MagentoAPITest.Program.Main(String[] args) in ....g\technolo 
gy\c#\MagentoAPITest\MagentoAPITest\Program.cs:line 30 
Press any key to continue . . . 

它似乎並不無論什麼樣的產品,我創造;我總是拋出這個錯誤。

我可以繼續添加產品;當我這樣做時,錯誤略微變爲(在50種產品的情況下)

Unhandled Exception: System.InvalidOperationException: There is an error in XML 
document (666, 2). ---> System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: complexObjectArray, result, ns1:catalogProductListResponseParam, SOAP-ENV:Body, SOAP-ENV:Envelope. Line 666, position 2. 

我相信,這意味着被Magento的發送適當的數據;然而,我懷疑C#沒有正確解析數據?

僅供參考,我找回我的產品通過:

public List<mage.catalogProductEntity> GetProducts() 
     { 
      //var result = ms.call(sessionID, "catalog_product.list", null); 



      // retrieve products 
      mage.filters filter = new mage.filters(); 
      mage.catalogProductEntity[] products = new mage.catalogProductEntity[1]; 
      try 
      { 

       products = ms.catalogProductList(sessionID, filter, ""); 
      } 
      catch (System.InvalidOperationException e) 
      { 
       Console.WriteLine(e.Message); 
       System.Xml.XmlException xe = (System.Xml.XmlException) e.InnerException; 
       Console.WriteLine(xe.SourceUri); 
       throw; 
      } 
      foreach (mage.catalogProductEntity product in products) 
      { 
       Console.WriteLine(product.product_id + ", " 
        + product.name + ", " 
        + product.type + ", " 
        + product.sku + ", " 
        + product.set + ""); 

      } 
      List<mage.catalogProductEntity> ProductsList = new List<mage.catalogProductEntity>(products); 
      return ProductsList; 
     } 

有誰知道爲什麼發生這種情況?

非常感謝!

回答

0

最有可能發生的情況是,請求了或者是因爲PHP的時間,或者數據庫(MySQL的猜測)。

你可以做什麼來測試,你有這條線: ms.catalogProductList(sessionID,filter,「」); 設置過濾器來提取一個特定的productID。然後只需循環播放產品列表,然後遞增productId。 (像「的productId公式12」)

如果所有的產品都可以拉這樣那麼很可能你的法師服務器上的超時/資源問題。如果不是,那麼它可能與特定產品有關。

假設您可以逐一獲取它們,那麼下一步就是通過在productID> X和ProductID < X + 10(或其他任意數字)上使用過濾器來減少對產品列表的調用次數你喜歡)。

0

這似乎與Magento的問題 嘗試搜索 「\ n」 和 「」 在

替換\ Magento的\ APP \代碼\核心\法師\阿比\型號\服務器\ WSI \適配器\ Soap.php (一previus備份是recomended; P) (最好的形式給出。將順延所涉及的類,但這個不僅是一個快速測試...)

0

問題絕對是\ Magento的\ APP \代碼\核心\法師\阿比\型號\服務器\ WSI \適配器\ Soap.php

我在C#中有這個問題數週! 它並不真正瞭解\ n。刪除它們,它應該工作

1

我們有Magento企業,並能找到一個解決,而無需修改核心!它很簡單,它的悲傷。我們的問題是,我們的PHP poutput像很多php服務器輸出一樣被gzip壓縮。在C#或PHP中,使用Web服務上的啓用退化標誌:

mservice.EnableDecompression = true; 

其中mservice是您的服務名稱。

0

與Magento 1.6.2.0和VisualBasic有同樣的問題。刪除所有不需要的空白後,它工作正常。 看起來"\n"與Windows世界中的crlf換行符不兼容(如果您想換行,可能應該是"\r\n")。

而不是調整核心文件,最好是在你自己的模塊中重寫類。

添加到您的MyCompany/MyModule/etc/config.xml

<config> 
<!-- other stuff --> 
<global> 
    <models>  
     <api> 
      <rewrite> 
       <server_wsi_adapter_soap>MyCompany_MyModule_Model_Server_WSI_Adapter_Soap</server_wsi_adapter_soap> 
      </rewrite> 
     </api> 
    </models> 
</global> 
</config> 

創建自己的適配器類MyCompany/MyModule/Model/Server/WSI/Adapter/Soap.php與調整後的run()方法:

class MyCompany_MyModule_Model_Server_WSI_Adapter_Soap extends Mage_Api_Model_Server_Adapter_Soap 
{ 
public function run(){ 

    $apiConfigCharset = Mage::getStoreConfig("api/config/charset"); 

    if ($this->getController()->getRequest()->getParam('wsdl') !== null) { 
     $wsdlConfig = Mage::getModel('api/wsdl_config'); 
     $wsdlConfig->setHandler($this->getHandler()) 
      ->init(); 
     $this->getController()->getResponse() 
      ->clearHeaders() 
      ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset) 
      ->setBody(
        preg_replace(
         '/(\>\s+\<)/i', // changed to match all whitespace enclosed by > and < 
         "><",   // replace it with just >< 
         str_replace(
           '<soap:operation soapAction=""></soap:operation>', 
           "<soap:operation soapAction=\"\" />", // removed the \n 
           str_replace(
             '<soap:body use="literal"></soap:body>', 
             "<soap:body use=\"literal\" />", // removed the \n 
             preg_replace(
              '/<\?xml version="([^\"]+)"([^\>]+)>/i', 
              '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>', 
              $wsdlConfig->getWsdlContent() 
             ) 
           ) 
         ) 
        ) 
      ); 
    } else { 
     try { 
      $this->_instantiateServer(); 

      $this->getController()->getResponse() 
       ->clearHeaders() 
       ->setHeader('Content-Type','text/xml; charset='.$apiConfigCharset) 
       ->setBody(
        preg_replace(
         '/(\>\s+\<)/i',  // same here 
         "><",    // and here 
         str_replace(
           '<soap:operation soapAction=""></soap:operation>', 
           "<soap:operation soapAction=\"\" />", // removed the \n 
           str_replace(
             '<soap:body use="literal"></soap:body>', 
             "<soap:body use=\"literal\" />", // removed the \n 
             preg_replace(
              '/<\?xml version="([^\"]+)"([^\>]+)>/i', 
              '<?xml version="$1" encoding="'.$apiConfigCharset.'"?>', 
              $this->_soap->handle() 
             ) 
           ) 
         ) 
        ) 
       ); 
     } catch(Zend_Soap_Server_Exception $e) { 
      $this->fault($e->getCode(), $e->getMessage()); 
     } catch(Exception $e) { 
      $this->fault($e->getCode(), $e->getMessage()); 
     } 
    } 

    return $this; 
} 
} 

這將輸出乾淨的XML與導致奇怪的錯誤,沒有不必要的字符。

相關問題