2010-02-24 63 views
0

我试图连接到Magento 1.4.0.1 API,但直到现在我没有运气。使用C#连接到Magento API

我加了Service Reference命名MagentoAPI并指出http://mydomain.com/api/v2_soap?wsdl=1(我知道=1无意,但它不没有工作)

这工作得很好,我得到的所有可用方法的列表,但是当我尝试使用它们中的任何一个都不起作用。

using Magento_Import.MagentoAPI; 

namespace Magento_Import 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     Mage_Api_Model_Server_V2_HandlerPortType handler; 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      string session = handler.login("username", "password"); 
     } 
    } 
} 

这就是我如何初始化网络服务,但是当我调试代码的handlernull

我在做什么错?

回答

5

好吧,我把它做这个工作:

using Magento_Import.MagentoAPI; 

namespace Magento_Import 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     Mage_Api_Model_Server_V2_HandlerPortTypeClient handler = new Mage_Api_Model_Server_V2_HandlerPortTypeClient(); 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      string session = handler.login("username", "password"); 

      catalogProductEntity[] products; 
      handler.catalogProductList(out products, session, null, null); 
     } 
    } 
} 

但林不知道这是最好的做法,如果有谁知道任何更好的方法来做到这一点请说出来:d

+1

这是在使用它们之前初始化对象是最好的实践。原因处理程序为null是因为您从未将其设置为值(即类的实例的值)。 – 2010-08-05 18:03:39