2
我正在通過ksoap2
製作外部數據庫!我的web服務工作正常,它將值插入到我的數據庫中,但通過android它不會發送任何值。我無法弄清楚什麼是錯誤!誰能幫幫我嗎?我有送(rollno名費)到我的數據庫通過ksoap2發送數據
這裏一個Button
和3 EditText
是我的代碼:
package com.example.externaldatabaseksoap2;
import java.io.IOException;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.R.string;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
Button enter;
EditText rollno,name,dues;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String NAMESPACE = "http://tempuri.org";
final String METHOD_NAME = "insert";
final String SOAP_ACTION = "http://tempuri.org/insert";
final String URL = "http://192.168.1.6:5000/Service.asmx";
rollno=(EditText)findViewById(R.id.etrollno);
name=(EditText)findViewById(R.id.etname);
dues=(EditText)findViewById(R.id.etdues);
enter=(Button)findViewById(R.id.enter);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Thread networkthread = new Thread(){
@Override
public void run() {
// TODO Auto-generated method stub
String r=rollno.getText().toString();
String n=name.getText().toString();
String d=dues.getText().toString();
try{
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("rollno");
pi.setValue(r);
pi.setType(int.class);
request.addProperty(pi);
PropertyInfo pi1 = new PropertyInfo();
pi1.setName("name");
pi1.setValue(n);
pi1.setType(String.class);
request.addProperty(pi1);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("dues");
pi2.setValue(d);
pi2.setType(String.class);
request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
//runOnUiThread (new Runnable(){
//public void run(){
//Toast.makeText(MainActivity.this,"Inserted", Toast.LENGTH_SHORT).show();
}
//});
//}
catch (Exception e){
e.printStackTrace();
//Toast.makeText(MainActivity.this,e.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
}
};
networkthread.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}