Chevy Mark Sunderland

Chevy Mark Sunderland

  • NA
  • 188
  • 166.8k

How To Call .Net Asmx Webservice In Android App

Feb 8 2014 12:21 PM
Hello everyone, I hope in your help.

I've this android application and I need connect to my hosting database with web service Asmx.
The webservice working in test browser.

In this code I don't have error but the output is empty, can you help me?
Thank you

package com.ccmex.myFirstApp;

import android.app.Activity;


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;


import android.os.Bundle;
import android.widget.TextView;


public class WebServiceDemoActivity extends Activity {


private final String NAMESPACE = "http://www.domainname.com/domainfolder/";
private final String URL = "http://www.domainname.com/domainfolder/folderWebService/StockService.asmx";
private final String SOAP_ACTION = "http://www.domainname.com/domainfolder/folderWebService/StockService";
private final String METHOD_NAME = "StockService";

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;

try {

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

androidHttpTransport.call(SOAP_ACTION, envelope);

TextView tv = new TextView(this);
tv.setText(response.toString());
setContentView(tv);

} catch (Exception e) {
e.printStackTrace();
}
}
}

Answers (2)