Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am trying call a c# web service using android application,using the eclipse and android emulater, the web service is also developed my me and the web service is works fine. but when i try access it through the andriod application it gives and exception as java.net.SocketTimeOutException. i gave the internet permission also. here is my code


public class Web01Activity extends Activity {
	
	
private static final String SOAP_ACTION = "http://tempuri.org/getadd";
	//private static final String SOAP_ACTION1 = "http://tempuri.org/getmul";

    private static final String METHOD_NAME = "getadd";

    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://localhost:51173/WebSite6/Service.asmx";

	
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final EditText tv=(EditText)findViewById(R.id.editText1);
        final EditText tv2=(EditText)findViewById(R.id.editText2);
        final EditText tv3=(EditText)findViewById(R.id.editText3);
        
   final    Button bt1=(Button)findViewById(R.id.button1);
   final    Button bt2=(Button)findViewById(R.id.button2);
       
    

   
     
      // bt11(num1,num2);
     

     
     bt1.setOnClickListener(new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			try
			{
				String name=tv.getText().toString();
				String nam=tv2.getText().toString();
				int num1=Integer.parseInt(name);
				int num2=Integer.parseInt(nam);
				
	            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
	            request.addProperty("a",num1 );
	            request.addProperty("b",num2);
	            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	            envelope.dotNet=true;
	            envelope.setOutputSoapObject(request);
	            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
	            androidHttpTransport.call(SOAP_ACTION, envelope);
	            Object result = (Object)envelope.getResponse();
	           tv3.setText(result.toString());
				
			}
			catch (Exception e) {
				tv3.setText(e.toString());
			}
						
		}
	});
       

--------------------------manifestfile------------------------------


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.padd.Web01"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Web01Activity"
            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>
<uses-permission android:name="android.permission.INTERNET"> </uses-permission>

</manifest>



plz help
Posted
Updated 15-Mar-12 0:08am
v4

1 solution

CSS
In Strung URL "localhost" means android device's localhost not the computer's

replace below

private static final String URL = "http://localhost:51173/WebSite6/Service.asmx";

with

private static final String URL = "http://10.0.2.2:51173/WebSite6/Service.asmx";
 
Share this answer
 

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



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