I have .net Web Service and I want to use it on android. This web service's methods return List(Of String) and I didn't get response on android. What can I do ? Here is the code..
I'm working on it for 3 days and I didn't find any solution yet.
In short, I need some list from .net web service and add this list's items to spinner. Please help me.
public class MainActivity extends Activity {
private Spinner myspinner;
private static final String METHOD_NAME = "Sektorler";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/Sektorler";
private static final String URL = "http://www.xxxxxxxxxx.com/webservice1.asmx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myspinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_main , SektorDoldur());
myspinner.setAdapter(adapter);
}
private ArrayList<String> SektorDoldur() {
ArrayList<String> sektorler = new ArrayList<String>();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
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);
SoapObject response = (SoapObject) envelope.getResponse();
if (response.hasProperty("String")) {
if (response.getPropertyAsString("String") == null) {
//do something
} else {
for(int i=0;i<response.getPropertyCount();i++){
// sektorler.add(i, response.getPropertyAsString("String"));
sektorler.add(response.getPropertyAsString(i));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sektorler;
}
Also I'm trying this code but it doesn't work.
public class MainActivity extends Activity {
private Spinner myspinner;
private static final String METHOD_NAME = "Sektorler";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/Sektorler";
private static final String URL = "http://www.xxxxxxxx.com/webservice1.asmx";
private String[] denemeList;
private String[] SektorDoldur(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
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);
SoapObject response = (SoapObject) envelope.bodyIn;
denemeList = new String[response.getPropertyCount()];
for(int i=0;i<response.getPropertyCount();i++){
denemeList[i] = response.getPropertyAsString(i).toString();
}
}
catch (Exception e) {
e.printStackTrace();
}
return denemeList;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SektorDoldur();
myspinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_main , denemeList);
myspinner.setAdapter(adapter);
}
I got it !!
this is false;
Lets see this code, it's true;
Finally there are some trick about it.
Open again Eclipse and Run Project!!