0
package com.example.soapconnect;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AsyncCallWS task = new AsyncCallWS();
        task.execute(); 


        //client = new DefaultHttpClient();            
        //new Read().execute("text");
 }


    private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
        @Override
        protected Void doInBackground(Void... params) {
           calculate();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {

        }

        @Override
        protected void onPreExecute() {

        }

        @Override
        protected void onProgressUpdate(Void... values) {

        }

    }

    public void calculate() 
    {
        final String OPERATION_NAME = "currDateTime";// your webservice web method name
        final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
        final String SOAP_ADDRESS = "https://taxi.bharathtravels.com/WebService.asmx";
        SOAP_ACTION = WSDL_TARGET_NAMESPACE + OPERATION_NAME;

        try { 


             SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
             PropertyInfo propertyInfo = new PropertyInfo();
             propertyInfo.type = PropertyInfo.STRING_CLASS;
             propertyInfo.name = "eid";
             edata =(EditText)findViewById(R.id.editText1);
             studentNo=edata.getText().toString();
           //  request.addProperty(propertyInfo, studentNo);
             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
             SoapEnvelope.VER11);
             envelope.dotNet = true;
             envelope.setOutputSoapObject(request);
             HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
             httpTransport.call(SOAP_ACTION, envelope);  
             Object response = envelope.getResponse();                    
             tvData1.setText(response.toString());


           // Log.i(TAG, "Result Celsius: " + resultString);
        }
        catch(Exception ex) {
            tvData1.setText(ex.toString()+"  Or enter number is not Available!");  
        }

        tvData1 = (TextView)findViewById(R.id.textView1);
    }
}

I am a newbie in android, and I'm trying to communicate .net code using web service. I have tried so many solutions, but I'm getting an error in

httpTransport.call(SOAP_ACTION, envelope); 

I would appreciate any help in resolving this, as I haven't been able to figure it out.

Jota
  • 17,281
  • 7
  • 63
  • 93

1 Answers1

0

Add the below line :

   setContentView(R.layout.activity_main);
    if (android.os.Build.VERSION.SDK_INT > 9)
    {
         StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
         StrictMode.setThreadPolicy(policy);
    }

under setContentView(R.layout.activity_main);

and for ssl Exception you can try:

public Client hostIgnoringClient() {
    try
    {
        SSLContext sslcontext = SSLContext.getInstance( "TLS" );
        sslcontext.init( null, null, null );
        DefaultClientConfig config = new DefaultClientConfig();
        Map<String, Object> properties = config.getProperties();
        HTTPSProperties httpsProperties = new HTTPSProperties(
                new HostnameVerifier()
                {
                    @Override
                    public boolean verify( String s, SSLSession sslSession )
                    {
                        return true;
                    }
                }, sslcontext
        );
        properties.put( HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, httpsProperties );
        config.getClasses().add( JacksonJsonProvider.class );
        return Client.create( config );
    }
    catch ( KeyManagementException | NoSuchAlgorithmException e )
    {
        throw new RuntimeException( e );
    }
}
Krupa Patel
  • 3,309
  • 3
  • 23
  • 28