0

I'm using the KSOAP2 library to call an ASP.NET web service. I'm not getting any error but I'm also not getting any response any idea to solve this.

Below is my code. Im simply calling the helloworld default method that returns a string.

    public class MainActivity extends Activity {

        private final String NAMESPACE = "http://tempuri.org/";
        private final String URL = "http://(ip)/TrialService.asmx";
        private final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
        private final String METHOD_NAME = "HelloWorld";
        TextView t1;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            t1 = (TextView) findViewById(R.id.textView1);

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            if (android.os.Build.VERSION.SDK_INT > 9) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                        .permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                String receivedInt = (String) envelope.getResponse();
                t1.setText(receivedInt);
                setContentView(t1);
            } catch (Exception e) {
                t1.setText("error");
            }
        }
    }       
Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
Farah
  • 55
  • 10

1 Answers1

0

First start off by enabling debugging, so that you can see the content of the soap envelope that you are sending to the server, you can do that by adding (see commented sections):

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;//ADD THIS
try {
     androidHttpTransport.call(SOAP_ACTION, envelope);
     //ADD THESE 2
     //Important Outputs to check how the request/Response looks like.. Check them in Logcat to find these outputs
     System.out.println("requestDump is :"+androidHttpTransport.requestDump);//ADDED
     System.out.println("responseDump is :"+androidHttpTransport.responseDump);//ADDED

     String receivedInt = (String) envelope.getResponse();
     t1.setText(receivedInt);
     setContentView(t1);
} catch (Exception e) {
        t1.setText("error");
}

Now you can see the soap envelope being sent to your server, check if it is accurate. (you can compare it with an envelope sent from your desktop using programs like SoapUI. )

Next:

  • You have to provide more details so we can help you better : put a copy of your relevant WSDL parts.

  • Make sure you are using the accurate values for : NAMESPACE, METHOD_NAME ,URL ,SOAP_ACTION

  • In case this is a test project and you have access to the server, you can have it as a bonus to check what happens on the server when u send the request.

For more references that can help you out see my answers at : link1 , link2 , link3 , link4

Community
  • 1
  • 1
ccot
  • 1,875
  • 3
  • 36
  • 54