HttpTransportSE ht = new HttpTransportSE (soapAction);
ht.debug = true;
try {
ht.call (soapAction, envelope);
if (envelope.getResponse ()! = null) {
SoapObject response = (SoapObject) envelope.bodyIn;
result = Integer.parseInt (response.getProperty ("LoginCheckResult") toString ().);
}
Execution to ht.call system collapsed
Use KSOAP2<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Nor is it too much to understand, is not it also have an open switch connected to it?
Reply:
Have, in the simulator can be, but a cell phone will not work to,
Reply:
Should be a mobile client privilege did not add it, you put the wrong message posted out
Reply:
The simulator also found another version of this problem, I do not know where the problem,
Reply:
Tips,, unfortunately has stopped
Reply:
The error message is printed out
Reply:
This is an example of what I wrote, you see.
Remember AndroidManifest.xml inside plus network privileges
package com.example.test;
import java.io.UnsupportedEncodingException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String NAMESPACE = "http://WebXml.com.cn/";
/ / WebService address
private static String URL = "http://www.webxml.com.cn/webservices/weatherwebservice.asmx";
private static final String METHOD_NAME = "getWeatherbyCityName";
private static String SOAP_ACTION = "http://WebXml.com.cn/getWeatherbyCityName";
private String weatherToday;
private TextView textView;
private Button okButton;
private SoapObject detail;
private Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg) {
textView.setText ((String) msg.obj);
Toast.makeText (MainActivity.this, detail.toString (),
. Toast.LENGTH_LONG) show ();
super.handleMessage (msg);
}
};
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
okButton = (Button) findViewById (R.id.btn_ok);
okButton.setOnClickListener (new Button.OnClickListener () {
public void onClick (View v) {
showWeather ();
}
});
textView = (TextView) findViewById (R.id.text);
}
private void showWeather () {
final String city = "Wuhan";
new Thread (new Runnable () {
@ Override
public void run () {
getWeather (city);
}
.}) Start ();
}
@ SuppressWarnings ("deprecation")
public void getWeather (String cityName) {
try {
System.out.println ("rpc ------");
SoapObject rpc = new SoapObject (NAMESPACE, METHOD_NAME);
System.out.println ("rpc" + rpc);
System.out.println ("cityName is" + cityName);
rpc.addProperty ("theCityName", cityName);
AndroidHttpTransport ht = new AndroidHttpTransport (URL);
ht.debug = true;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (
SoapEnvelope.VER11);
envelope.bodyOut = rpc;
envelope.dotNet = true;
envelope.setOutputSoapObject (rpc);
ht.call (SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
detail = (SoapObject) result
. GetProperty ("getWeatherbyCityNameResult");
System.out.println ("result" + result);
System.out.println ("detail" + detail);
parseWeather (detail);
Message msg = handler.obtainMessage ();
msg.obj = weatherToday;
handler.sendMessage (msg);
} Catch (Exception e) {
e.printStackTrace ();
}
}
private void parseWeather (SoapObject detail)
throws UnsupportedEncodingException {
String date = detail.getProperty (6) toString ();.
weatherToday = "Today:" + date.split ("") [0];
weatherToday = weatherToday + "\ n Weather:" + date.split ("") [1];
weatherToday = weatherToday + "\ n temperature:"
+ Detail.getProperty (5) toString ();.
weatherToday = weatherToday + "\ n Wind:"
. + Detail.getProperty (7) toString () + "\ n";
System.out.println ("weatherToday is" + weatherToday);
}
}
Reply:
Error message in the Eclipse logcat window
No comments:
Post a Comment