开发者

Connect to the Magento API using C#

开发者 https://www.devze.com 2022-12-21 07:24 出处:网络
Im trying to connect to the Magento 1.4.0.1 API, but until now I have no luck. I have added a Service Reference named MagentoAPI and pointed it to http://mydomain.com/api/v2_soap?wsdl=1 (I know the =

Im trying to connect to the Magento 1.4.0.1 API, but until now I have no luck.

I have added a Service Reference named MagentoAPI and pointed it to http://mydomain.com/api/v2_soap?wsdl=1 (I know the =1 is not intended, but it dont work without)

This works fine, I get a list of all available methods, but when I t开发者_开发技巧ry to use any of them it dont work.

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");
        }
    }
}

That is how I initialize the web service, but when I debug the code the handler is null.

What am I doing wrong?


Ok, I got it working by doing this:

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);
        }
    }
}

But im not sure this is the best practice, if anyone knows any better ways to do this please say so :D

0

精彩评论

暂无评论...
验证码 换一张
取 消