how to handle android request of username & password in jax-ws

Go To StackoverFlow.com

0

I try to create web service, code for webservice client of android appliaction as below:

String SOAP_ACTION = "";
String METHOD_NAME = "operation1";
String NAMESPACE = "http://service.livebackup.com/";
String URL = "http://192.168.1.3:8084/test/webService?wsdl";

Button signin;
Thread t;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    signin = (Button) findViewById(R.id.btn_sign_in);
    signin.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
                showDialog(0);
                t=new Thread() {
                    public void run() {
                            tryLogin();
                      }

                };
          t.start();
          }
    });

}

private void tryLogin() {
    // TODO Auto-generated method stub
    EditText etxt_user = (EditText) findViewById(R.id.txt_username);
    EditText etxt_pass = (EditText) findViewById(R.id.txt_password);
    String username = etxt_user.getText().toString();
    String password = etxt_pass.getText().toString();

    callWebService(username,password);
}

private void callWebService(String username, String password) {
    // TODO Auto-generated method stub

    //String result = "ishan";
     try {
         int no=2;
         SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
      AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

       PropertyInfo p1 = new PropertyInfo();
       Check C = new Check();//use check KvmSerializable{
       C.UserName=username;
       C.PassWord=password;


       p1.setName("C");
       p1.setValue(C);
       p1.setType(C.getClass());
       request.addProperty(p1);
               SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
           envelope.dotNet=false;
                       envelope.setOutputSoapObject(request);
                   androidHttpTransport.call(SOAP_ACTION, envelope);
                   Log.v("Ok","wait for response");
                   Object results =(Object)envelope.getResponse();


                   Log.v("Ok","Connection has response object" +results);

                   Log.v("Ok","jj");
                   //to get the data String resultData=result.getProperty(0).toString();
                   String temp = results.toString();

                   Log.v("Ok","Connection has response" +temp);
     }
     catch (Exception e) {
        // TODO: handle exception
            System.out.println("Error:" +e.getClass().getName()+":"+e.getMessage());

    }

}

check class as follow:

public class Check implements KvmSerializable{

 public String UserName;
 public String PassWord;

 public Check(){}

 public Check(String userName, String passWord) {
        super();
        UserName = userName;
        PassWord = passWord;
    }

 @Override
public Object getProperty(int arg0) {
    // TODO Auto-generated method stub

     switch(arg0)
     {
     case 0:
         return UserName;
     case 1:
         return PassWord;
     }

    return null;
}

@Override
public int getPropertyCount() {
    // TODO Auto-generated method stub
    return 2;
}



@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
    // TODO Auto-generated method stub

     switch(index)
     {
     case 0:
         info.type = PropertyInfo.INTEGER_CLASS;
         info.name = "UserName";
         break;
     case 1:
         info.type = PropertyInfo.INTEGER_CLASS;
         info.name = "PassWord";
         break;

     default:break;
     }


}

@Override
public void setProperty(int index, Object value) {
    // TODO Auto-generated method stub

    switch(index)
    {
    case 0:
        UserName = value.toString();
        break;
    case 1:
        PassWord = value.toString();
        break;
    default:
        break;
    }
}
}

My problem: i use net beans jax-ws on server side, how to i handle a request of username & password from android ws -client,

i complete done with only request.addproperty("userName",username);

plz,help..

2012-04-03 19:31
by Gandhi Ishan


0

First of all, in your client: UserName and PassWord are Strings, but you treated them as int. In Check class do this:

@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
    switch(index) {
        case 0:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "UserName";
            break;
        case 1:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = "PassWord";
            break;
        default:
            break;
}

Remove wsdl at the end of your URL string:

String URL = "http://192.168.1.3:8084/test/webService/";

In your server: check it out http://www.ibm.com/developerworks/webservices/library/ws-android/index.html

Hope it helps.

2012-04-05 18:00
by Enrique Marcos
thank you,but my problem is not on client side but on server side.i not receive parameter value "username","password" on server side,only null value to receive. in shortly i send only one object on server side "C" and i confuse in how to receive object in jax-ws server side .i already check this link but this method receive one string parameter not object. i thing now u understand my problem better - Gandhi Ishan 2012-04-06 06:50
Ok, I'm not familiarized with jax-ws server side. Hopefully someone can help ypu - Enrique Marcos 2012-04-06 11:17
Ads