vou colocar uma classe exemplo de como consumir um webService soap,
com a lib ksoap:
import java.io.InputStream;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class ExemploWSActivity extends Activity implements Runnable {
private AndroidHttpTransport transporte;
private TextView textView1;
private String namespace = "http://www.oorsprong.org/websamples.countryinfo";
private String METHOD_NAME = "CountryFlag";
private String URL = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso";
private String SOAP_ACTION = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=CountryFlag";
private SoapObject soap;
private SoapSerializationEnvelope envelope;
private ProgressDialog progress;
private SoapPrimitive resposta;
private Drawable drawable;
private ImageView imgView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgView = (ImageView) findViewById(R.id.imageView1);
Button btnOK = (Button) findViewById(R.id.button1);
final EditText txtNome = (EditText) findViewById(R.id.editText1);
btnOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
soap = new SoapObject(namespace, METHOD_NAME);
PropertyInfo p1 = new PropertyInfo();
p1.setName("sCountryISOCode");
p1.setValue(txtNome.getText().toString());
p1.setType(String.class);
soap.addProperty(p1);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true;
envelope.setOutputSoapObject(soap);
transporte = new AndroidHttpTransport(URL);
progress = ProgressDialog.show(ExemploWSActivity.this, "Carregando", "Aguarde...", true, false);
Thread th = new Thread(ExemploWSActivity.this);
th.start();
}
});
}
public void run() {
try {
transporte.call(SOAP_ACTION, envelope);
resposta = (SoapPrimitive) envelope.getResponse();
drawable = loadIMG(resposta.toString());
handler.sendEmptyMessage(0);
} catch (Exception ex) {
Log.d("Erro = ", ex.getMessage());
}
}
private Drawable loadIMG(String url) {
try {
InputStream is = (InputStream) new java.net.URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
progress.dismiss();
imgView.setImageDrawable(drawable);
}
};
}
pronto!
para baixar o jar.
https://code.google.com/p/ksoap2-android/downloads/detail?name=ksoap2-android-assembly-2.4-jar-with-dependencies.jar&can=2&q=
Vitor Yudi Hansen