Search code examples
androidwcfsoap-clientxml-deserializationandroid-ksoap2

Error in deserializing body of request message for operation wcf in android studio


Below is my android code where i am trying to consume one SOAP web services which is .svc?WSDL But it is giving me the below ERROR(error is after this code) even though its working fine when I tested in SoapUI application. can anyone please help me to solve this issue, i have tried so many things after googling but no luck..

package sa.com.abana.testws;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class MainActivity extends Activity {

    String METHOD_NAME = "getStringVal";
    String SOAP_ACTION = "http://tempuri.org/IService1/getStringVal";
    String NAMESPACE = "http://tempuri.org/IService1/";
    String  SOAP_URL = "http://qasim.com.sa:90/Service1.svc?wsdl";


    SoapPrimitive resultString;
    String TAG = "Response";
    String tempValue="Pakistan";
//    SoapObject request;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        CelsiusAsync celsiustofahr = new CelsiusAsync();
        celsiustofahr.execute();
    }
    private class CelsiusAsync extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            try {
                SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
                Request.addProperty("str1", tempValue);

                SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                soapEnvelope.dotNet = true;
                soapEnvelope.setOutputSoapObject(Request);

                HttpTransportSE transport = new HttpTransportSE(SOAP_URL);

                transport.call(SOAP_ACTION, soapEnvelope);
                //Object obj = (Object)soapEnvelope.getResponse();
                resultString = (SoapPrimitive) soapEnvelope.getResponse();
                //SoapObject resp = (SoapObject)soapEnvelope.getResponse();
                Log.i(TAG, "Result Celsius: " + resultString);
            } catch (Exception ex) {
                Log.e(TAG, "Error: " + ex.getMessage());
            }
            return null;
        }
    }
}

Error

SoapFault - faultcode: 'a:InternalServiceFault' faultstring: 'Error in deserializing body of request message for operation 'getStringVal'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'getStringVal' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'getStringVal' and namespace 'http://tempuri.org/IService1/'' faultactor: 'null' detail: org.kxml2.kdom.Node@424a7188


Solution

  • i was able to solve this issue just adjust the below line

    OLD

    String NAMESPACE = "http://tempuri.org/IService1/";
    

    NEW & Correct

    String NAMESPACE = "http://tempuri.org/";