Search code examples
androidksoap2

SoapFault - faultcode 'Sender' faultstring


Im using ksoap2 to consume a web service application but show the error 'SoapFault - faultcode: 'Sender' faultstring: 'WEBSERVICE ERROR : Soap Prefix Missing'.

I noticed that the ksoap2 adds words in my tag. Example xml received:

<CUSRID i:type="d:string">teste</CUSRID><CPASSID i:type="d:string">teste</CPASSID><CUPC i:type="d:string">produto</CUPC>

This is the original tags:

<CUSRID>STRING</CUSRID><CPASSID>STRING</CPASSID><CUPC>STRING</CUPC>

And this is my code android:

    private static final String SOAP_ACTION = "http://187.75.181.76:8090/RETORNASTK";
private static final String METHOD_NAME = "RETORNASTK";
private static final String NAMESPACE = "http://187.75.181.76:8090/";
private static final String URL = "http://187.75.181.76:8090/ws/WSAPPSTOCK.apw";

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

      Bundle extras = data.getExtras();
      String result = extras.getString("SCAN_RESULT");
      EditText desc = (EditText) findViewById(R.produto.desc);
      desc.setText(result);    

      SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

      Request.addProperty("CUSRID","teste");
      Request.addProperty("CPASSID","teste");
      Request.addProperty("CUPC",result);

      SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

      soapEnvelope.setOutputSoapObject(Request);

      HttpTransportSE http_transport = new HttpTransportSE(URL);

      try {
          http_transport.call(SOAP_ACTION,soapEnvelope);

          SoapObject obj, obj1, obj2;
          obj = (SoapObject) soapEnvelope.getResponse();
          obj1 = (SoapObject) obj.getProperty("STRUCTSTK");

          for (int i = 0; i < obj1.getPropertyCount(); i++) { 
      // the method getPropertyCount() and  return the number of rows
                  obj2 = (SoapObject) obj1.getProperty(i);
                  obj2.getProperty(0).toString();// value of column 1
                  obj2.getProperty(1).toString();// value of column 2
                  // like that you will get value from each column
              }

      } catch (Exception e) {
          e.printStackTrace();
      } 


  }

Solution

  • I Solved the problem creating a heritage from class SoapSerializationEnvelope.

    I changed this properties too.

          soapEnvelope.implicitTypes=true;
          soapEnvelope.setAddAdornments(false);
    

    Like this:

    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import java.io.IOException;
    import org.xmlpull.v1.XmlSerializer;
    
    public class SoapSerEnv extends SoapSerializationEnvelope {
    
    public SoapSerEnv(int version) {
        super(version);
        // TODO Auto-generated constructor stub
    }
    
    public void write(XmlSerializer writer)
        throws IOException
    {
        writer.setPrefix("i", xsi);
        writer.setPrefix("d", xsd);
        writer.setPrefix("c", enc);
        writer.setPrefix("soapenv", env); // era writer.setPrefix("v", env)
        writer.startTag(env, "Envelope");
        writer.startTag(env, "Header");
        writeHeader(writer);
        writer.endTag(env, "Header");
        writer.startTag(env, "Body");
        writeBody(writer);
        writer.endTag(env, "Body");
        writer.endTag(env, "Envelope");
    }
    

    }