3

I am trying to call a web service from Android client using the ksoap library.

Here is my android code

private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.16.0.230/WebService/Test.asmx";
TextView tv;

public void call()
{
    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("name", "zawoad");

        SoapSerializationEnvelope envelope = new          SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        androidHttpTransport.call(SOAP_ACTION, envelope);

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

        tv.setText(result);
    } catch (Exception e) {
        tv.setText("exception :" + e.getLocalizedMessage());
        }
}

And here is my web service method which is written in Test.asmx file

[WebMethod]
public string HelloWorld(string name)
{
    return "Hello World" + name;
}

When the androidHttpTransport.call(SOAP_ACTION, envelope); line is executed it throws the following exception

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @2:44 in java.io.InputStreamReader@43e593c8)

Please help..

2 Answers 2

2

This is working code

private static final String SOAP_ACTION = "http://tempuri.org";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.16.0.230/WebService/Test.asmx?wsdl";
/*write ?wsdl only for local system testing*/

TextView tv;

public void call()
{
    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("name", "zawoad");

        SoapSerializationEnvelope envelope = new          SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet=true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,20000);//Updated

        androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive  resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
        String result = resultsRequestSOAP.toString();

        tv.setText(result);
    } catch (Exception e) {
        tv.setText("exception :" + e.getLocalizedMessage());
        }
}
Sign up to request clarification or add additional context in comments.

Comments

0

The calling that you are performing will not happen. what is the web service return type? We can pass the values and call that.

Comments

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.