我试图使用ksoap在Android上使用点网络服务。一切似乎都很好,但我得到的反应是错误的。
internet permission is set in the manifest file.
可能出错?
package com.bible; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; //import com.bible.R.string; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; public class BibleActivity extends Activity { private final String NAMESPACE = "http://www.webserviceX.NET/"; private final String URL = "http://www.webservicex.net/BibleWebservice.asmx"; private final String SOAP_ACTION = "http://www.webserviceX.NET/GetBibleWordsbyKeyWord "; private final String METHOD_NAME = "GetBibleWordsbyKeyWord "; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Thread networkThread = new Thread() { @Override public void run() { SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME); String book = "love"; // String Chapter = "3"; // String verse = "16"; PropertyInfo bookProp = new PropertyInfo(); bookProp.setName("BibleWords"); bookProp.setValue(book); bookProp.setType(String.class); request.addProperty(bookProp); // PropertyInfo chapProp =new PropertyInfo(); // chapProp.setName("chapter"); // chapProp.setValue(Chapter); // chapProp.setType(string.class); // request.addProperty(chapProp); // // PropertyInfo vProp =new PropertyInfo(); // vProp.setName("Verse"); // vProp.setValue(verse); // vProp.setType(string.class); // request.addProperty(vProp); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); final SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); // Object response = envelope.getResponse(); // final SoapObject response = (SoapObject) envelope.bodyIn; Log.i("myApp", response.toString()); runOnUiThread(new Runnable() { public void run() { // TextView tv = new TextView(this); // TextView tv = (TextView) // findViewById(R.id.textView4); TextView tv = (TextView) findViewById(R.id.TextView2); tv.setText(response.toString()); setContentView(tv); } }); } catch (Exception e) { e.printStackTrace(); } } }; networkThread.start(); } }