Guys Here is a code, that 100% works. i find many solutions but all are crap.
First of all if you are using WCF then you must use .net framework 3.5 otherwise it will not work.
use AsyncTask<string,string,string> java class for AsyncTasks, because networking programs never work in main Thread.
Use this ip 10.0.2.2, others ip don't work. This ip is for android emulator. android virtually made this ip. Lan ip doesn't assign to android emulator.
Here is a code. And never forget to mention:
<uses-permission android:name="android.permission.INTERNET"/>
in manifest.xml.
package com.example.webservicesexample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Sync().execute("","","");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
package com.example.webservicesexample;
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 android.content.AsyncTaskLoader;
import android.os.AsyncTask;
import android.util.Log;
public class Sync extends AsyncTask<String,String,String>{
private final String SOAP_NAMESPACE="http://tempuri.org/";
private final String SOAP_URL="http://10.0.2.2:17303/Service1.svc";
private final String SOAP_ACTION="http://tempuri.org/IService1/GetData";
private final String SOAP_METHOD_NAME="GetData";
private SoapObject request;
@Override
protected String doInBackground(String... params) {
request=new SoapObject(SOAP_NAMESPACE,SOAP_METHOD_NAME);
PropertyInfo _info = new PropertyInfo();
_info.setType(String.class);
_info.setName("name");
_info.setValue("qasim");
request.addProperty(_info);
SoapSerializationEnvelope envp = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envp.dotNet=true;
envp.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envp);
}catch(Exception ex)
{
Log.d("Exception",ex.toString());
}
return null;
}
}