Pelo que vi está faltando o SOAP_ACTION no método Call():
httpTransport.call("", envelope);
Creio que isso lhe ajude a entender melhor a comunicação usando o KSoap2:
2014/1/8 Douglas Henrique <douglasjvah@gmail.com>
Boa noite galera, sou iniciante em android, por isso pode ser que meu erro(duvida) seja simples. Bom, estou desenvolvendo uma aplicação que se comunica com o webservice, só que está dando um erro na hora que eu crio o SoapObject. O WebService parece está funcionando normalmente, no browser posso visualizar o WSDL atraves do endereço http://127.0.0.1:9876/calc normalmente.--
. Logo abaixo está o web service:
@WebService
@SOAPBinding(style = Style.RPC)
public interface CalculadoraServer {
@WebMethod float soma(float num1, float num2);
}
WebService(endpointInterface = "calc.CalculadoraServer")
public class CalculadoraServerImpl implements CalculadoraServer {
@Override
public float soma(float num1, float num2) {
return num1 + num2;
}
}
public class CalculadoraServerPublisher {
public static void main(String[] args)
{
Endpoint.publish("http://127.0.0.1:9876/calc",
new CalculadoraServerImpl());
}
}
E agora minha aplicação android:
public class MainActivity extends Activity implements OnClickListener, Runnable {
private Handler handler = new Handler();
private ProgressDialog dialog;
private static final String URL="http://127.0.0.1:9876/calc";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.btsoma);
b.setOnClickListener(this);
}
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(this, "Exemplo","Calculando com web service");
new Thread(this).start();
}
public void run(){
EditText text1 = (EditText) findViewById(R.id.editn1);
EditText text2 = (EditText) findViewById(R.id.editn2);
final TextView textSoma = (TextView) findViewById(R.id.viewsoma);
float n1 = Float.parseFloat(text1.getText().toString());
float n2 = Float.parseFloat(text2.getText().toString());
try{
Calculadora calculadora = new Calculadora(URL);
final String soma = calculadora.somar(n1,n2);
handler.post(new Runnable() {
@Override
public void run() {
textSoma.setText("Soma: "+soma);
Log.i("ws", String.valueOf(soma));
textSoma.setVisibility(View.VISIBLE);
}
});
}catch(Exception e){
Log.e("ws",e.getMessage(),e);
}finally{
dialog.dismiss();
}
}
}
public class Calculadora {
private final String url;
public Calculadora(String url){
this.url = url;
}
public String somar(float n1, float n2) throws IOException, XmlPullParserException{
SoapObject soap = new SoapObject("urn:calc", "soma");
soap.addProperty("num1", n1);
soap.addProperty("num2", n2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(soap);
Log.i("ws", "Chamando Web Service: "+url);
HttpTransportSE httpTransport = new LivroHttpTransport(url);
httpTransport.call("", envelope);
Object soma = envelope.getResponse();
Log.i("ws","Soma: "+soma);
return soma.toString();
}
}
public class LivroHttpTransport extends HttpTransportSE{
public LivroHttpTransport(String s){
super(s);
}
@Override
public void call(String s, SoapEnvelope soapenvelope) throws IOException, XmlPullParserException{
byte bytes[] = createRequestData(soapenvelope);
String envelope = new String(bytes);
Log.i("ws", "Envelope: "+envelope);
super.call(s, soapenvelope);
}
}
O erro está ocorrendo na classe Calculadora, nessa linha:
SoapObject soap = new SoapObject("urn:calc", "soma");
O erro que ocorre:
01-07 19:58:43.613: E/AndroidRuntime(23486): FATAL EXCEPTION: Thread-1763
01-07 19:58:43.613: E/AndroidRuntime(23486): Process: com.example.calculadora, PID: 23486
01-07 19:58:43.613: E/AndroidRuntime(23486): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
01-07 19:58:43.613: E/AndroidRuntime(23486): at com.example.calculadora.Calculadora.somar(Calculadora.java:22)
01-07 19:58:43.613: E/AndroidRuntime(23486): at com.example.calculadora.MainActivity.run(MainActivity.java:47)
01-07 19:58:43.613: E/AndroidRuntime(23486): at java.lang.Thread.run(Thread.java:841)
Alguem saberia me explicar o porque do erro ? Desde já, muito obrigado.
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
سمووحخ ̷̴̐ خ ̷̴̐ خ ̷̴̐ خ امارتيخ ̷̴̐ خ
Analista-Programador
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário