Estou com problema para acessar um serviço via SOAP.
segue meu código, se alguém indicar um erro, fico grato.
import java.util.ArrayList;
import java.util.List;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.content.Context;
import android.widget.Toast;
public enum Icicle {
INSTANCE;
private String SOAP_ACTION = "";
private String METHOD_NAME = "login";
private String NAMESPACE = "http://server.webservice.com.br/";
private String URL = "";
private String serviceResponse;
private String sellerID;
private List<String> historico = new ArrayList<String>();
private Context currentContext;
public Context getCurrentContext() {
return currentContext;
}
public void setCurrentContext(Context currentContext) {
this.currentContext = currentContext;
}
public List<String> getHistorico() {
return historico;
}
public void setHistorico(List<SoapPrimitive> historico) {
this.historico.clear();
for(int i=0;i<historico.size();i++)
this.historico.add(historico.get(i).toString());
}
public String getSOAP_ACTION() {
return SOAP_ACTION;
}
public void setSOAP_ACTION(String sOAP_ACTION) {
SOAP_ACTION = sOAP_ACTION;
}
public String getMETHOD_NAME() {
return METHOD_NAME;
}
public void setMETHOD_NAME(String mETHOD_NAME) {
METHOD_NAME = mETHOD_NAME;
}
public String getNAMESPACE() {
return NAMESPACE;
}
public void setNAMESPACE(String nAMESPACE) {
NAMESPACE = nAMESPACE;
}
public String getURL() {
return URL;
}
public void setURL(String uRL) {
URL = uRL;
}
public String getServiceResponse() {
return serviceResponse;
}
public void setServiceResponse(String response) {
this.serviceResponse = response;
}
public String getSellerID() {
return sellerID;
}
public void setSellerID(String sellerID) {
this.sellerID = sellerID;
}
public SoapSerializationEnvelope callService(SoapObject request){
// this.setSOAP_ACTION(this.getNAMESPACE() + "/" + this.getMETHOD_NAME());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(Icicle.INSTANCE.getURL());
try {
ht.debug = true;
ht.call(Icicle.INSTANCE.getSOAP_ACTION(), envelope);
} catch (Exception e) {
e.printStackTrace();
}
return envelope;
}
public void getPrimitiveResponse(SoapSerializationEnvelope envelope){
SoapPrimitive response = null;
String retorno = "Erro na resposta do servidor!";
try {
response = (SoapPrimitive)envelope.getResponse();
} catch (SoapFault e) {
e.printStackTrace();
}
catch(NullPointerException e){
Toast.makeText(getCurrentContext(), "Erro na troca de mensagens com o servidor!", Toast.LENGTH_LONG).show();
}
if(response!=null){
retorno = response.toString();
}
this.setServiceResponse(retorno);
}
public void getCollectionResponse(SoapSerializationEnvelope envelope){
KvmSerializable response = null;
try{
response = (KvmSerializable)envelope.bodyIn;
}catch(NullPointerException e){
Toast.makeText(getCurrentContext(), "Erro na troca de mensagens com o servidor!", Toast.LENGTH_LONG).show();
}
if(response!=null){
List><SoapPrimitive> objects = new ArrayList<SoapPrimitive>();
for (int i = 0; i < response.getPropertyCount(); i++) {
objects.add((SoapPrimitive) response.getProperty(i));
}
this.setHistorico(objects);
}
}
}