Disclaimer: I AM a newbie at Android programming :( I have seen a similar question posted here, but the solution did not work for me. I AM trying to meet all the criteria for a properly posted question so please bear with me. I wrote a C# client to test my wcf service (SimpleHTTPTransport) and it works fine over WiFi from a second computer so I know there are no firewall issues. My Android browser can hit http://10.0.0.134:4444/DietService.svc?msdl with no problem. THe service is set for anonymous user, so no login info necessary. I've checked out every possible reference I could find here and elsewhere on the web for 2 days with no help. I'm using ksoap2 2.5.2 and can't get anything to work. I've even tried setting up an Async Task. I've copied allegedly "working" code and still can't get any comm to the wcf service. At this point, I'm totally stumped. Here is my stack trace, code and the variables at the time of transmission:
Stack Trace:
org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)
diet.diet.MainActivity$AsyncCaller.doInBackground(MainActivity.java:113)
diet.diet.MainActivity$AsyncCaller.doInBackground(MainActivity.java:83)
android.os.AsyncTask$2.call(AsyncTask.java:295)
java.util.concurrent.FutureTask.run(FutureTask.java:237)
android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
java.lang.Thread.run(Thread.java:818)
CODE:
package diet.diet;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private static final Integer TIMEOUT = 60000;
private static final String METHOD_NAME = "GetFoodName";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.0.134:4444/DietService.svc";
final static String SOAP_ACTION = "http://tempuri.org/IDietService/GetFoodName";
Button btn_Request;
TextView tv_Reply;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
btn_Request = (Button) findViewById(R.id.btn_Request);
btn_Request.setOnClickListener(this);
tv_Reply = (TextView) findViewById(R.id.tv_Reply);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
tv_Reply.setText("Got it");
new AsyncCaller().execute();
}
private class AsyncCaller extends AsyncTask<Void, Void, Void>
{
private String resultData;
ProgressDialog pdLoading = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
pdLoading.setMessage("Loading...");
pdLoading.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("id", "7");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
Log.i("CYBERON", "Check 1");
envelope.setOutputSoapObject(request);
Log.i("CYBERON", "Check 2");
HttpTransportSE myHttpTransport = new HttpTransportSE(URL, TIMEOUT);
myHttpTransport.debug = true;
try {
myHttpTransport.call(SOAP_ACTION, envelope);
}
catch (Exception e)
{
StackTraceElement[] stack = e.getStackTrace();
String Trace = "";
for(StackTraceElement line : stack)
{
Trace += line.toString();
Trace += "\n";
}
// Log.i("CYBERON", "Exception caught");
// Log.i("CYBERON", "RESPONSE: " + myHttpTransport.responseDump);
}
Log.i("CYBERON", "Check 3");
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
Log.i("CYBERON", "Check 4");
//to get the data
resultData = result.toString();
// 0 is the first object of data
Log.i("CYBERON", "Check 5");
} catch (Exception e) {
Log.i("CYBERON", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
pdLoading.dismiss();
tv_Reply.setText(resultData);
}
}
}
This is what I can find when I break on myHttpTransport.call:
this = {MainActivity$AsyncCaller@4404}
params = {Void[0]@4412}
request = {SoapObject@4413} "GetFoodName{id=7; }"
name = {String@4439} "GetFoodName"
namespace = {String@4440} "http://tempuri.org/"
properties = {Vector@4441} size = 1
attributes = {Vector@4442} size = 0
shadow$_klass_ = {Class@4392} "class org.ksoap2.serialization.SoapObject"
shadow$_monitor_ = -1920603187
envelope = {SoapSerializationEnvelope@4414}
addAdornments = true
classToQName = {Hashtable@4429} size = 5
dotNet = true
idMap = {Hashtable@4430} size = 0
implicitTypes = false
multiRef = null
properties = {Hashtable@4431} size = 0
qNameToClass = {Hashtable@4432} size = 5
bodyIn = null
bodyOut = {SoapObject@4413} "GetFoodName{id=7; }"
name = {String@4439} "GetFoodName"
namespace = {String@4440} "http://tempuri.org/"
properties = {Vector@4441} size = 1
attributes = {Vector@4442} size = 0
shadow$_klass_ = {Class@4392} "class org.ksoap2.serialization.SoapObject"
shadow$_monitor_ = -1920603187
enc = {String@4433} "http://schemas.xmlsoap.org/soap/encoding/"
count = 41
hashCode = -891961955
shadow$_klass_ = {Class@3919} "class java.lang.String"
shadow$_monitor_ = -1900538580
encodingStyle = null
env = {String@4434} "http://schemas.xmlsoap.org/soap/envelope/"
count = 41
hashCode = -1487983936
shadow$_klass_ = {Class@3919} "class java.lang.String"
shadow$_monitor_ = -2032362507
headerIn = null
headerOut = null
version = 110
xsd = {String@4435} "http://www.w3.org/2001/XMLSchema"
xsi = {String@4436} "http://www.w3.org/2001/XMLSchema-instance"
shadow$_klass_ = {Class@4395} "class org.ksoap2.serialization.SoapSerializationEnvelope"
shadow$_monitor_ = -1922298750
myHttpTransport = {HttpTransportSE@4415}
connection = null
debug = true
requestDump = null
responseDump = null
timeout = 60000
url = {String@4426} "http://10.0.0.134:4444/DietService.svc"
count = 38
hashCode = -193616475
shadow$_klass_ = {Class@3919} "class java.lang.String"
accessFlags = 8912913
classLoader = null
classSize = 666
clinitThreadId = 967
componentType = null
dexCache = {DexCache@4508}
dexCacheStrings = {String[41837]@4509}
dexClassDefIndex = 1399
dexTypeIndex = 1366
directMethods = 1877705544
iFields = 1875422136
ifTable = {Object[6]@4510}
name = {String@4473} "java.lang.String"
numDirectMethods = 39
numInstanceFields = 2
numReferenceInstanceFields = 0
numReferenceStaticFields = 2
numStaticFields = 4
numVirtualMethods = 55
objectSize = 0
primitiveType = 131072
referenceInstanceOffsets = 0
sFields = 1875422072
status = 10
superClass = {Class@2987} "class java.lang.Object"
verifyErrorClass = null
virtualMethods = 1877707104
vtable = null
shadow$_klass_ = {Class@735} "class java.lang.Class"
shadow$_monitor_ = 1263145082
shadow$_monitor_ = -1984993388
xmlVersionTag = {String@4427} ""
count = 0
hashCode = 0
shadow$_klass_ = {Class@3919} "class java.lang.String"
shadow$_monitor_ = -2067490254
shadow$_klass_ = {Class@4403} "class org.ksoap2.transport.HttpTransportSE"
shadow$_monitor_ = -2124603501
myHttpTransport.debug = true