我已经使用 Ksoap2 连接到了 asp.net 服务,它连接良好,但有一件事是我以 XML 形式返回响应。无论如何我可以让它以普通文本显示。
这是我使用的代码
public class AndroidWebService extends Activity {
/** Called when the activity is first created. */
private static String SOAP_ACTION = "http://tempuri.org/GetHelpDeskCalls";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "GetHelpDeskCalls";
static final String URL = "https://198.125.364:8080/AndroidServices/Service1.asmx";
Button getData;
EditText userID;
TextView data;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.helpdesk);
getData = (Button) findViewById(R.id.button1);
userID = (EditText) findViewById(R.id.txtFar);
data = (TextView) findViewById(R.id.textView1);
Thread nT = new Thread() {
@Override
public void run() {
getData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME);
request.addProperty("userID", userID.getText()
.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
// androidHttpTransport.call(SOAP_ACTION, envelope);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
final String ss = androidHttpTransport.responseDump;
// final SoapObject response = (SoapObject) envelope
// .getResponse();
runOnUiThread(new Runnable() {
public void run() {
data.setText(ss.toString());
}
});
} catch (Exception e) {
data.setText("Error");
}
}
});
}
};
nT.start();
}
}