0

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 try 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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

It is very much so best practice to initialise your objects before using them. The reason handler is null is because you never set it to a value (ie. the value of the instance of a class).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.