2

Im trying to use ksoap2 with a webservice in android but I think i cannot get a respond from the webservice. Anyone knows why i get this error? "org.xmlpull.v1.XmlPullParserException: expected: START_TAG"

my code is:

public class ANDROIDsapActivity extends Activity {
    /** Called when the activity is first created. */
    private static final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
    private static final String URL = "http://192.168.2.5:8000/sap/bc/srt/wsdl/bndg_E0DFBFD4F407C3F1A6A000155D02060A/wsdl11/allinone/ws_policy/document?sap-client=500";    
    private static final String SOAP_ACTION = "zws_get_customer";
    private static final String METHOD_NAME = "ZfGetCustomers";
        TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.textView1);

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        Request.addProperty("IM_NAME","M");

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

        soapEnvelope.encodingStyle = SoapSerializationEnvelope.ENC2003;
        soapEnvelope.bodyOut = Request;
        soapEnvelope.dotNet = true;
        soapEnvelope.encodingStyle = SoapSerializationEnvelope.XSD;

       // AndroidHttpTransport aht = new AndroidHttpTransport(URL);
        HttpTransportSE aht = new HttpTransportSE(URL);
        aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
        headers.add(new HeaderProperty("Authorization",  "basic " +
                Base64.encode("username:password".getBytes())));

        try {
            aht.call(SOAP_ACTION, soapEnvelope,headers);
            SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();
            tv.setText("Status: " + resultString);
        } catch (Exception e) {
            // TODO: handle exception
            tv.setText(e.toString());
        }
    }
}

my complete error is :

org.xmlpull.v1.XmlPullParserException: expected: START_TAG  
{http://schemas.xmlsoap.org/soap/envelope/} Envelope  
(position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions  
targetNamespace='urn:sap-com:document:sapsoap:functions:mc-style'>  
@1:630 in java.io.InputStreamReader@43e50a10

I'm stuck in this error and I cant go any further. Please help!

EDIT: I HAVE SOLVED THIS. PLEASE READ MY ANSWER BELOW ON COMMENTS AND ANSWERS. I HOPE I'LL BE HELPFUL FOR SOMEONE IN SOMEWAY.

6
  • Please check your SOAP_ACTION.I think it should be NAMESPACE+"/"+METHOD_NAME. If this doesn't work then tell me I will help you further. Commented Sep 16, 2011 at 8:42
  • I still get the same error. I'm thinking that my URL doesnt work. Because in my webservice its not like my URL. Its not an IP but a web address. Do you think that it could be the problem? Commented Sep 16, 2011 at 12:40
  • Please check that if you fire the URL in browser it should return a WSDL or any message related to that service. Commented Sep 16, 2011 at 12:44
  • I have tried to change SOAP_ACTION but i think my error is not related to SOAP_ACTION because no matter what value I gave to SOAP_ACTION, I got the same exception/error. I even gave null to SOAP_ACTION and got the same error. My code stucks on this line : aht.call(SOAP_ACTION, soapEnvelope,headers); Commented Sep 19, 2011 at 11:20
  • Why are you using headers,is there any certificate used for authenticating some stuff?If not then don't use them.Otherwise you have to use HttpsTransportSE method for certification purpose. Commented Sep 19, 2011 at 12:55

1 Answer 1

1

I have solved my problem by just changing the web service style. Use Restful webservice system instead of SOAP if you want to integrate SAP and android.

Sign up to request clarification or add additional context in comments.

2 Comments

hi mtu iam also getting same problem but i didnt understand what you are saying. iam facing this in android. please can you explain it in clear..
Hi sando, If you try to integrate a SAP web-service with android app, I believe you need to use RESTFUL type of webservice which is available in android, not SOAP. Please consider looking deeper in Restful Webservices in android.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.