【问题标题】:Connect to the Magento API using C#使用 C# 连接到 Magento API
【发布时间】:2010-02-24 18:10:18
【问题描述】:

我正在尝试连接到 Magento 1.4.0.1 API,但直到现在我都没有运气。

我添加了一个名为MagentoAPIService Reference 并将其指向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");
        }
    }
}

这就是我初始化 Web 服务的方式,但是当我调试代码时,handlernull

我做错了什么?

【问题讨论】:

    标签: c# web-services api magento


    【解决方案1】:

    好的,我这样做了:

    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

    【讨论】:

    • 在使用对象之前初始化对象是非常好的做法。处理程序为 null 的原因是因为您从未将其设置为值(即类实例的值)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多