|
|
|
android เรียก webservice ปตท ไม่ได้ results เป็น null เหมือนเดิม ช่วยหน่อยครับ |
|
|
|
|
|
|
|
ช่วยดูหน่อยครับ งง มาหลายวันละ TT ทำไมมัน เรียกเว็บ service ไม่ได้
error
10-21 07:09:05.051 29561-30030/com.example.arkar_000.asas E/WebServiceExample﹕ Soap object Error
นี่ code
Code (Android-Java)
package com.example.arkar_000.asas;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import java.util.ArrayList;
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public class PlaceholderFragment extends Fragment {
private Button btnClick; // activity bottom
private TextView tView; // test space text value
private ArrayAdapter<String> AdapterXML;
private ArrayList<String> ListitemXML = new ArrayList<String>();
private SoapPrimitive results = null; // veriable type SoapPrimitive
private String URL = "http://www.pttplc.com/pttinfo.asmx"; // url webservice
private String NAMESPACE = "http://www.pttplc.com/ptt_webservice/"; // default value webservice
private String METHOD_NAME = "CurrentOilPrice"; // method that request webservice
private String SOAP_ACTION = "http://www.pttplc.com/ptt_webservice/CurrentOilPrice"; // use call method webservice
;
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_my, container, false);
btnClick = (Button) rootView.findViewById(R.id.button);
tView = (TextView) rootView.findViewById(R.id.textView1);
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callWebService();
}
});
return rootView;
}
public void callWebService(){
Thread s = new Thread() {
public void run() {
SoapObject callPtt = new SoapObject(NAMESPACE,METHOD_NAME); // create soapObject
callPtt.addProperty("Language", "TH"); // sent parameter to method webservice
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11 ); // determine format and version of soap
envelope.dotNet = true; // determine dotnet
envelope.setOutputSoapObject(callPtt);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject rS = (SoapObject) envelope.bodyIn;
String results = rS.toString(); // results in type SoapPrimitive
}
catch (Exception e) {
// check error
results= null;
}finally {
if (results == null){
Log.e("WebServiceExample", "Soap object Error");
}
else { // result not null
;
goCovert();
}
}
อ้างอิงจาก https://www.thaicreate.com/mobile/forum/083690.html
ผม ขอ permission internet และ import ksoap แล้ว
Tag : Mobile, Android, JAVA, Mobile, Web Service
|
|
|
|
|
|
Date :
2014-10-21 07:28:25 |
By :
REGISTER |
View :
1244 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
URL ของ Web Services นั้นยังใช้ได้ปกติหรือเปล่าครับ ทดสอบง่าย ๆ ด้วยการเรียกตรง ๆ ผ่าน Web Browser ครับ
|
|
|
|
|
Date :
2014-10-22 14:23:30 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|