Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created java activity.. like below... But my code doesn't work


package com.web.ws;

import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.serialization.SoapPrimitive;
import org.xmlpull.v1.XmlPullParserException;

public class WSActivity extends Activity {
    /** Called when the activity is first created. */
	
	private static final String SOAP_ACTION = "http://tempuri.org/GetDepCode";
	private static final String METHOD_NAME = "GetDepCode";
	private static final String NAMESPACE = "http://tempuri.org/";
	private static final String URL = "http://localhost:100/Service.asmx";
	TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.tv);
        
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo pi = new PropertyInfo();
        pi.setName("QCode");
        pi.setValue("0473");
        pi.setType(PropertyInfo.INTEGER_CLASS);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		//envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		
		
		
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
		androidHttpTransport.debug = true;
		try {	
			androidHttpTransport.call(SOAP_ACTION, envelope);
			SoapPrimitive sp=SoapPrimitive)envelope.getResponse(); 
			tv.setText("Value:"+sp);
			} 
		catch (IOException e) {e.printStackTrace();	}
                catch (XmlPullParserException e) {e.printStackTrace();}
	
    }
}


and Manifest


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    package="com.web.ws"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minsdkversion="15" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application>
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity>
            android:name=".WSActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Posted
Updated 3-Jul-12 23:10pm
v2

1 solution

Hello,

Replace the following

Java
private static final String URL = "http://localhost:100/Service.asmx";


with

Java
private static final String URL = "http://10.0.2.2:100/Service.asmx";



Check this dear Localhost[^]
 
Share this answer
 
Comments
Sant Osha 5-Jul-12 5:22am    
private static final String URL = "http://10.0.2.2:100/Service.asmx";
This code by you hasn't work...
I use my IP address instead of localhost

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900