How To Call .Net Asmx Webservice In Android App

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 3

Feb 8, 2014 7:04:30 PM via Website

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
1package com.ccmex.myFirstApp;
2
3import android.app.Activity;
4
5
6import org.ksoap2.SoapEnvelope;
7import org.ksoap2.serialization.SoapObject;
8import org.ksoap2.serialization.SoapPrimitive;
9import org.ksoap2.serialization.SoapSerializationEnvelope;
10import org.ksoap2.transport.HttpTransportSE;
11
12
13import android.os.Bundle;
14import android.widget.TextView;
15
16
17public class WebServiceDemoActivity extends Activity {
18
19
20private final String NAMESPACE = "h t t p : / / w w w .domainname.com/domainfolder/";
21private final String URL = "h t t p : / / w w w .domainname.com/domainfolder/folderWebService/StockService.asmx";
22private final String SOAP_ACTION = "h t t p : / / w w w .domainname.com/domainfolder/folderWebService/StockService";
23private final String METHOD_NAME = "StockService";
24
25public void onCreate(Bundle savedInstanceState)
26{
27super.onCreate(savedInstanceState);
28setContentView(R.layout.main);
29
30SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
31SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
32envelope.setOutputSoapObject(request);
33envelope.dotNet = true;
34
35try {
36
37SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
38HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
39
40androidHttpTransport.call(SOAP_ACTION, envelope);
41
42TextView tv = new TextView(this);
43tv.setText(response.toString());
44setContentView(tv);
45
46} catch (Exception e) {
47e.printStackTrace();
48}
49}
50}