Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

peter bebok
peter bebok
7,841 Points

WebService can't login

Hello, I want to write an app that can login to magento (online store). link to wsdl on my serwer is ip adress/index.php/api/v2_soap?wsdl=1 but what to type in NAMESPACE and SOAP_ACTION , i want to call login method from megento API Please help. My code is below

public class WebService { //Namespace of the Webservice - can be found in WSDL private static String NAMESPACE = "???????????????"; //Webservice URL - WSDL File location
private static String URL = "ipadresindex.php/api/v2_soap?wsdl=1";//Make sure you changed IP address //SOAP Action URI again Namespace + Web method name private static String SOAP_ACTION = "??????????";

public static boolean invokeLoginWS(String userName,String passWord, String webMethName) {
    boolean loginStatus = false;
    // Create request
    SoapObject request = new SoapObject(NAMESPACE, webMethName);
    // Property which holds input parameters
    PropertyInfo unamePI = new PropertyInfo();
    PropertyInfo passPI = new PropertyInfo();
    // Set Username
    unamePI.setName("admin");
    // Set Value
    unamePI.setValue(userName);
    // Set dataType
    unamePI.setType(String.class);
    // Add the property to request object
    request.addProperty(unamePI);
    //Set Password
    passPI.setName("******");
    //Set dataType
    passPI.setValue(passWord);
    //Set dataType
    passPI.setType(String.class);
    //Add the property to request object
    request.addProperty(passPI);
    // Create envelope
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    // Set output SOAP object
    envelope.setOutputSoapObject(request);
    // Create HTTP call object
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        // Invoke web service
        androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
        // Get the response
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        // Assign it to  boolean variable variable
        loginStatus = Boolean.parseBoolean(response.toString());

    } catch (Exception e) {
        //Assign Error Status true in static variable 'errored'
        CheckLoginActivity.errored = true;
        e.printStackTrace();
    } 
    //Return booleam to calling object
    return loginStatus;
}

}

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I haven't used a SOAP web service in a while; your best bet is to try searching for "Android SOAP client example" (or tutorial). Sorry I'm not more help here!