1

I want get the response from a SAP SOAP Web service but I get an Exception.

I'm using the following code:

package com.veee.pack;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import java.io.IOException;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportBasicAuth;
import org.ksoap2.transport.HttpTransportSE;
import org.w3c.dom.Element;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class WeservicesExampleActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //getting these values from wsdl file
       //username and password appended as URL Parameters
         final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
         final String URL = "http://*********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user******&sap-password=************";
         final String METHOD_NAME = "Z_GET_CUST_GEN";
         final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";

        SoapObject request =new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("Input", "1460");
        request.addProperty("Langu", "d");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

        envelope.setOutputSoapObject(request);

        HttpTransportSE httptransport=new HttpTransportSE(URL);
        httptransport.debug = true;
        try {

          //calling the services
         httptransport.call(SOAP_ACTION, envelope);

         Object result = (Object) envelope.getResponse();

        //getting the Response Here.

         System.out.println("Result" + result.toString());

        }
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

When I debug the Application it terminates at

httptransport.call(SOAP_ACTION, envelope); 

I ran some examples by using ksoap2 in android it is working fine. I got the following exception in my logcat:

04-24 12:19:17.935: WARN/System.err(1569): java.net.SocketTimeoutException
04-24 12:19:17.935: WARN/System.err(1569):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)

Please give any suggestion to overcome this issue or send how can i make request and receive the response through XML in Android.

Thanks in advance.....

Jens
  • 16,241
  • 4
  • 50
  • 50
  • 1
    `java.net.SocketTimeoutException` seems to imply that you are trying to communicate with a service that isn't open. Assuming that your `URL` address points to a SAP service only exposed on your internal net - how are you connecting to it, WiFi only? Can you use Wireshark (or similar) to check if you're even connecting to it? – Jens Apr 24 '12 at 09:24
  • Thanks for ur Reply i Am using Wired net but soapui pro its is working Fine how can make it fast – Venkatasubbaiah Atluru Apr 24 '12 at 09:47
  • in Android emulator is there any settings needed for that ? – Venkatasubbaiah Atluru Apr 24 '12 at 09:47
  • Wired net? Never heard of that network analyzer. In any case, since you're apparently running on an emulator - what are you seeing in your connection logs in the network analyzer? Are you using a [proxy](http://stackoverflow.com/questions/2437366/android-emulator-internet-access) in your network? Can you, using the default web browser in the emulator, browse to some random website such as www.google.com? – Jens Apr 24 '12 at 10:17
  • Yes i am using Wired net on my computer.it would be a Router based network.i am surf some sites in android emulator browser it is working fine for me – Venkatasubbaiah Atluru Apr 24 '12 at 10:26
  • whenever i am putting internet permision on app it shows other wise it canot opne ? – Venkatasubbaiah Atluru Apr 24 '12 at 10:31

3 Answers3

1

AVoid using SOAP in android.. because it is not recommended.

Use Restful webservices which is officialy suported by android. If your webservice provider is unable to provide Restful service,...bear with some problems like the app will not work some times and may not work in some of the android devices.

To get rid of problems with your ksoap2 impleentation play with multiple ksoap2 drivers, put the logic of network calls in a separate thread.

The call to httptransport.call(SOAP_ACTION, envelope); consumes huge memory, more time and hence avoid using this call in main thread. Try in a new create emulator and one of the devices. KSOAP2 works 20 to 50% of android devices. Some times it may not work in a device from a same manufacturer, for example it may work in HTC sense 2.3.4 and may not work in ver 2.3.5 of HTC Sense.

It is recommended to use Restful Webservices.

Sree Rama
  • 1,116
  • 11
  • 24
0

A socketTimeoutException occurs when the socket cannot read or accept within a certain interval. You should always be prepared for something like this and use try/catch in your code to handle these situations.

To access web services in general; make sure your app has the android.permission.INTERNET in it's manifest and check that the web service can be reached from the emulator. You can use the code from this post to check if your service is reachable.

Community
  • 1
  • 1
THelper
  • 14,136
  • 6
  • 59
  • 95
0

You can set the timeout limit manually by using ksoap2 library 2.5.2 with dependencies by using

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,Time_Out);
Lalit Poptani
  • 65,659
  • 21
  • 155
  • 238