Search code examples
androidmagentoandroid-ksoap2

Error in getting session id from magento web service using ksoap2


private static final String NAMESPACE = "urn:Magento";
private static final String URL = "http://example.com/api/v2_soap";
private static final String METHOD="login";
private static final String ACTION="urn:Magento/login";
String sessionId,error;   

    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD);

        request.addProperty("username", "xxxxxx");
        request.addProperty("apiKey", "xxxxxx");

        SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        env.dotNet = true;
        env.xsd = SoapSerializationEnvelope.XSD;
        env.enc = SoapSerializationEnvelope.ENC;

        env.setOutputSoapObject(request);

        AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);            
        androidHttpTransport.debug=true;
        androidHttpTransport.call("", env);

        Object res = env.getResponse();
        sessionId=res.toString();
        Log.v("sessionId", sessionId);

        }catch (Exception e){
            error=e.getMessage();
            Log.v("Soapfault",error);
        }

this is the code i am using. I am getting SocketTimeoutException. I have tried all other answers which are given in stack overflow for this SocketTimeoutException related questions but still getting same error. Can anyone help me please?


Solution

  • Don't use AndroidHttpTransport its deprecated. instead of this use

    HttpTransportSE httpTransportSE=new HttpTransportSE(URL)

    Updated:

    https://www.yireo.com/tutorials/magebridge/administration/596-step-by-step-create-a-magento-api-user

    check this link and create those credentials and use this in your code. After that your problem will be solved...

    Happy coding