IBM provides a wonderful tutorial how to access WSDL service from Android device
Example provided in the tutorial gives clear understanding how KSoap library usage works. But during integrating this example in my project, I found that getting result is not working as described in the tutorial.
Here is the fixed example:
package android.webservice.client; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import org.ksoap2.serialization.PropertyInfo; import android.widget.TextView; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class AndroidWSClient extends Activity { private static final String NAMESPACE = "http://hello_webservice/"; private static String URL = "http://192.168.1.68:7001/HelloWebService/HelloWSService?WSDL"; private static final String METHOD_NAME = "hello"; private static final String SOAP_ACTION = "http://hello_webservice/hello"; private TextView lblResult; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lblResult = (TextView) findViewById(R.id.result); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); PropertyInfo propInfo=new PropertyInfo(); propInfo.name="arg0"; propInfo.type=PropertyInfo.STRING_CLASS; request.addProperty(propInfo, "John Smith"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); SoapObject resultsRequestSOAP = (SoapObject)envelope.bodyIn; lblResult.setText(resultsRequestSOAP.getPropertyAsString("result")); //"result" is the array, which is reported by WebService } catch (Exception e) { } } }
I want to send 3 parameters to wsdl.One of them is arraylist.To send this arraylist I defined a class like this:
public class busStop implements KvmSerializable{
public int busStopId ;
public float latitude;
public float longitude;
// Empty constructor
public busStop(){
}
public busStop(int busStopId,float latitude,float longitude,byte[] soundFile)
{
this.busStopId = busStopId;
this.latitude = latitude;
this.longitude = longitude;
}
@Override
public Object getProperty(int arg0) {
switch(arg0)
{
case 0:
return busStopId;
case 1:
return latitude;
case 2:
}
return null;
}
public int getPropertyCount() {
return 3;
}
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.type = PropertyInfo.INTEGER_CLASS;
info.name = “busStopId”;
break;
case 1:
info.type = Float.class;
info.name = “latitude”;
break;
case 2:
info.type = Float.class;
info.name = “longitude”;
break;
default:break;
}
}
public void setProperty(int index, Object value) {
switch(index)
{
case 0:
busStopId = Integer.parseInt(value.toString());
break;
case 1:
latitude = Float.parseFloat(value.toString());
break;
case 2:
longitude = Float.parseFloat(value.toString());
break;
default:
break;
}
}
}
For float values I define customize class like this:
public class MarshalFloat implements Marshal
{
public Object readInstance(XmlPullParser parser, String namespace, String name,
PropertyInfo expected) throws IOException, XmlPullParserException {
return Float.parseFloat(parser.nextText());
}
public void register(SoapSerializationEnvelope cm) {
cm.addMapping(cm.xsd, “float”, Float.class, this);
}
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
writer.text(obj.toString());
}
}
But I have a extra parameter for busstop class.Its type is byte[].I don’t know how can I create class for this parameter.Do you have any idea about it or another way to send arraylist which consist of different type of data to send wsdl as a parameter?
i want make an android app using wsdl services plz help me how i can passing login user name and hash password
Hi,
you just add login/password in the following way:
propInfo.name=”login”;
propInfo.type=PropertyInfo.STRING_CLASS;
request.addProperty(propInfo, “some_username”);
propInfo.name=”password”;
propInfo.type=PropertyInfo.STRING_CLASS;
request.addProperty(propInfo, “some_password”);