zawoad
zawoad

Reputation: 136

Can not call C# .net Web Service method from Android client

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..

Upvotes: 3

Views: 1489

Answers (2)

Atif Mahmood
Atif Mahmood

Reputation: 8992

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());
        }
}

Upvotes: 2

DAS
DAS

Reputation: 696

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

Upvotes: 0

Related Questions