嘗試這個代碼:
public class TabelActivity extends AppCompatActivity {
private static String SOAP_ACTION = "http://tempuri.org/GetIDSSupportData";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "GetIDSSupportData";
//change url here
private static String URL = "http://166.62.119.183:8066/IDSSupportData.asmx";
String pksupportid,userid,username,email,subject,desc,entrydate,modatetime,issolved,imgsrc;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table);
if (Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
bt = (Button) findViewById(R.id.bt);
//add button listener
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Pageno","1");
request.addProperty("PageSize","20");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject) envelope.bodyIn;
if (result != null) {
//Get the first property and change the label text
Log.i("result", result.toString());
/* JSONObject jsonObj = new JSONObject(result.toString());
Log.i("jobj",jsonObj.toString());*/
/* Gson gson = new Gson();
String json = gson.toJson(result.toString());*/
//Log.i("json",json);
TableLayout tv = (TableLayout) findViewById(R.id.maintable);
tv.removeAllViewsInLayout();
SoapObject root = (SoapObject) result.getProperty(0);
// Log.i("root", root.toString());
SoapObject s_deals = (SoapObject) root.getProperty("NewDataSet");
// Log.i("sd0", s_deals.toString());
int flag = 1;
for(int i= -1;i<s_deals.getPropertyCount();i++){
TableRow tr = new TableRow(TabelActivity.this);
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
if (flag == 1) {
TextView b6 = new TextView(TabelActivity.this);
b6.setText("Id");
b6.setTextColor(Color.BLUE);
b6.setTextSize(15);
tr.addView(b6);
TextView b19 = new TextView(TabelActivity.this);
b19.setPadding(10, 0, 0, 0);
b19.setTextSize(15);
b19.setText("Name");
b19.setTextColor(Color.BLUE);
tr.addView(b19);
TextView b29 = new TextView(TabelActivity.this);
b29.setPadding(10, 0, 0, 0);
b29.setText("Status");
b29.setTextColor(Color.BLUE);
b29.setTextSize(15);
tr.addView(b29);
tv.addView(tr);
final View vline = new View(TabelActivity.this);
vline.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
vline.setBackgroundColor(Color.BLUE);
tv.addView(vline);
flag = 0;
}
else {
SoapObject s_deals_1 = (SoapObject) s_deals.getProperty(i);
pksupportid = s_deals_1.getProperty("PkSupportId").toString();
userid = s_deals_1.getProperty("UserId").toString();
username = s_deals_1.getProperty("UserName").toString();
email = s_deals_1.getProperty("EmailId").toString();
subject = s_deals_1.getProperty("Subject").toString();
desc = s_deals_1.getProperty("Description").toString();
issolved = s_deals_1.getProperty("IsSolved").toString();
entrydate = s_deals_1.getProperty("EntryDate").toString();
imgsrc = "http://media.westsidechevrolet.com/houston/624064%20wtf.jpg";
TextView b = new TextView(TabelActivity.this);
String stime = pksupportid;
b.setText(stime);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr.addView(b);
TextView b1 = new TextView(TabelActivity.this);
b1.setPadding(10, 0, 0, 0);
b1.setTextSize(15);
String stime1 = username;
b1.setText(stime1);
b1.setTextColor(Color.BLACK);
tr.addView(b1);
TextView b2 = new TextView(TabelActivity.this);
b2.setPadding(10, 0, 0, 0);
String stime2 = desc;
b2.setText(stime2);
b2.setTextColor(Color.BLACK);
b2.setTextSize(15);
tr.addView(b2);
tv.addView(tr);
final View vline1 = new View(TabelActivity.this);
vline1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
vline1.setBackgroundColor(Color.WHITE);
tv.addView(vline1);
}
}
} else {
Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
清單檔案中的
:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
附加jar文件在你的lib folde [R ksoap2-機器人組裝-2.4-JAR-與-dependencies.jar在你的應用水平gradle這個文件
:
compile fileTree(include: '*.jar', dir: 'libs')
compile files('libs/ksoap2-android-assembly-2.4-jar-with-dependencies.jar')
請改變你的代碼,並檢查它:
public void Calculate() {
String SOAP_ACTION = "http://www.w3schools.com/xml/CelsiusToFahrenheit";
String METHOD_NAME = "CelsiusToFahrenheit";
String NAMESPACE = "http://www.w3schools.com/xml/";
String URL = "http://www.w3schools.com/xml/tempconvert.asmx";
try {
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("Celsius", getCel);
SoapSerializationEnvelope soapEnvelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport = new HttpTransportSE(URL);
transport.call(SOAP_ACTION, soapEnvelope);
resultString = (SoapPrimitive) soapEnvelope.getResponse();
Log.i(TAG, "Result Celsius: " + resultString);
} catch (Exception ex) {
Log.e(TAG, "Error: " + ex.getMessage());
}
Plz chk此網址:http://www.w3schools.com/webservices/tempconvert.asmx它不起作用 –
請提供您有哪些演示使用? –
所以網站不工作。一切都好嗎? –