我有.NET Web服务,我想用它在Android上。 此Web服务的方法返回列表(串),我没有得到Android上的响应。 我能做什么 ? 这里是代码..
我工作的这3天,我没有找到任何解决办法呢。
总之,我需要从.NET Web服务的一些清单,并加入该列表中的项目,以微调。 请帮我。
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;
}
我也正在尝试这种代码,但它不工作。
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);
}