ksoap2 org.xmlpull.v1.xmlpullparserexception expected start_tag error

Below solution is tested and used for WCF Web Services

If you are getting this error

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>
@1:7 in java.io.InputStreamReader@41afb3f0)"

Then the possible chances are that your code is not able to access the web service as it has not been provided with correct values of

METHOD_NAME="";
NAMESPACE ="";      
SOAP_ACTION ="";
URL ="";

I struggled a lot to find these basic but important values to run ksoap2

METHOD_NAME="";
NAMESPACE ="";      
SOAP_ACTION ="";
URL ="";

There were various examples which actualy told me the theory behind this value thats how to generate them like wise
SOAP_ACTION = NAMESPACE + METHOD_NAME.

And I kept on experimenting with various combinations with no Result.

A guy like me who is having little experience with WebServices and Ksoap2 and had woirked with JSON most of the time
actually get frustated, what the heck these values are and how to get them correctly.

You will never ever face difficulty in finding out these values after going thru the below procedure.

Run your WebService

1. WebService

It will show you a window like this to you.

Picture 1 webservice

2. WSDL

Now Open Its WSDL File by clicking on the link marked in the pick to look at its WSDL

It will something look like this.

picture 2 wsdl

3.To get Namespace for the WebService

Now search for string “Namespace” using Ctrl+F

You will get something like this

picture 3 namespace

Here you will notice that we have two namespaces

targetNamespace="http://tempuri.org/">
<wsdl:import namespace="iscservices.dedicated.co.za"

now which one to consider we will find out later-on in the following steps

Now which one to use you will find out later

4. To get Method Name and its Corresponding SoapAction

Look for your method you want to access
"PutRecipeImagesPost" in this case

Picture 4 Soap Action

You will see there is SOAP Action also here for this method.

As in Soap action is NameSpace + Methodname
and here we can see its using "iscservices.dedicated.co.za"
so the same we will finalize as our namespace

5. To get URL

Look for the string "soap:address location"

see the picture below

The value of this attribute will be your URL

So eventually we get all our required values.

values according to our example

METHOD_NAME="PutRecipeImagesPost";
NAMESPACE ="iscservices.dedicated.co.za";       
SOAP_ACTION ="iscservices.dedicated.co.za/InterfaceiPhysioIntelWCFService/PutRecipeImagesPost";
URL ="http://10.0.2.2:51809/iPhysioIntelService.svc/second/";

If you are not able to see the above snapshots or not able to get the values for these in you WSDl then tell the
WebService deveoper to fix that up.

Later on how to use KSoap2

see the below snippet

SoapObject req = new SoapObject(NAMESPACE,METHOD_NAME);
            //SoapObject req = new SoapObject(Namespace_Server,MethodName_Server);

    //req.addProperty(KEY, VALUE);
//Key : - parameter name that is there in URL of webservice
//value:- value we want to send to the parameter
    req.addProperty("ImageData", data);
    req.addProperty("login", CommonStaticData.getusername());
    req.addProperty("password",CommonStaticData.getpassword());
    req.addProperty("recipeId",FileID);

    MarshalBase64 mbase = new MarshalBase64();// marshal is used to serialize the byte array

    SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelop.bodyOut = req;
    envelop.encodingStyle = SoapSerializationEnvelope.ENC2001;
    envelop.dotNet = true;
    envelop.setOutputSoapObject(req);


    HttpTransportSE aht = new HttpTransportSE(URL);

    mbase.register(envelop);


    aht.call(SOAP_ACTION,envelop);

Leave a Comment