Android web servisleri expected: START_TAG hatası
13.07.2016 - 10:37
package tr.com.inspira.ucar.test;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class MainActivity extends AppCompatActivity {
EditText txtTC;
EditText txtAd;
EditText txtSoyad;
EditText txtDogumYili;
Button btnDogrula;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtTC = (EditText) findViewById(R.id.txtTC);
txtAd = (EditText) findViewById(R.id.txtAd);
txtSoyad = (EditText) findViewById(R.id.txtSoyad);
txtDogumYili = (EditText) findViewById(R.id.txtDogum);
btnDogrula = (Button) findViewById(R.id.btnDogrula);
btnDogrula.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TCKimlikNoInput tcKnoInput = new TCKimlikNoInput();
tcKnoInput.setTcKimlikNo(Long.parseLong(txtTC.getText().toString()));
tcKnoInput.setAd(txtAd.getText().toString());
tcKnoInput.setSoyad(txtSoyad.getText().toString());
tcKnoInput.setDogumYili((Integer.parseInt(txtDogumYili.getText().toString())));
TCKimlikAsyncTask lt = new TCKimlikAsyncTask();
lt.input = tcKnoInput;
lt.execute("");
}
});
}
private class TCKimlikAsyncTask extends AsyncTask<String, Void, String> {
public TCKimlikNoInput input;
public boolean sonuc = false;
@Override
protected String doInBackground(String... urls){
WebServiceCaller i = new WebServiceCallerImpl();
sonuc = i.TcKimlikNoDogrula(input);
return "";
}
@Override
protected void onPostExecute(String result){
//Toast.makeText(null,"Doğrulama Sonucu : " + sonuc, Toast.LENGTH_LONG).show();//değiştirildi
// MessageBar.show("This is a message");
display(0);
}
private void display(int i) {
System.out.println("Kimlik Sonucu : " + sonuc);
}
/*@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//Toast.makeText(this, _details[position], Toast.LENGTH_LONG).show();
AlertDialog.Builder adb=new AlertDialog.Builder(CurrentActvity.this);
adb.setTitle("Title");
adb.setMessage(_details[position]);
adb.setPositiveButton("Ok", null);
adb.show();
}*/
}
public class WebServiceCallerImpl implements WebServiceCaller {
private static final String NAMESPACE = "http://tckimlik.nvi.gov.tr/WS/";
private static final String SERVICE_URL = "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx";
private static final String DOGRULA_METHOD_ACTION = "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula";
private static final String DOGRULA_METHOD = "TCKimlikNoDogrula";
@Override
public boolean TcKimlikNoDogrula(TCKimlikNoInput input) {
SoapObject request = new SoapObject(NAMESPACE, DOGRULA_METHOD);
request.addProperty("TCKimlikNo", input.getTcKimlikNo());
request.addProperty("Ad", input.getAd());
request.addProperty("Soyad", input.getSoyad());
request.addProperty("DogumYili", input.getDogumYili());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
//envelope.avoidExceptionForUnknownProperty = true;
envelope.dotNet = true;
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setAddAdornments(false);
envelope.implicitTypes = false;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(SERVICE_URL);
System.out.print("-1");
try {
System.out.print("0");
androidHttpTransport.call(DOGRULA_METHOD_ACTION, envelope);
System.out.print("1");
if (envelope.bodyIn instanceof SoapObject) {
SoapObject soapObject = (SoapObject) envelope.bodyIn;
TCKimlikNoResult tcKimlikNoDogrulaResult =
new Gson().fromJson((JsonElement) soapObject.getProperty(0), //değişiklik yaptın
TCKimlikNoResult.class);
System.out.print("2");
return tcKimlikNoDogrulaResult.TCKimlikNoDogrulaResult;
} else if (envelope.bodyIn instanceof SoapFault) {
System.out.print("3");
SoapFault soapFault = (SoapFault) envelope.bodyIn;
throw new Exception(soapFault.getMessage());
}
} catch (Exception e) {
System.out.print("Catch\n");
return false;
}
System.out.print("TcKimlikNoDogrula\n");
return false;
}
}
private class TCKimlikNoInput {
private Long tcKimlikNo;
private String ad;
private String soyad;
private int dogumYili;
public Long getTcKimlikNo() {
return tcKimlikNo;
}
public void setTcKimlikNo(Long tcKimlikNo) {
this.tcKimlikNo = tcKimlikNo;
}
public String getAd() {
return ad;
}
public void setAd(String ad) {
this.ad = ad;
}
public String getSoyad() {
return soyad;
}
public void setSoyad(String soyad) {
this.soyad = soyad;
}
public int getDogumYili() {
return dogumYili;
}
public void setDogumYili(int dogumYili) {
this.dogumYili = dogumYili;
}
}
public interface WebServiceCaller {
boolean TcKimlikNoDogrula(TCKimlikNoInput input);
}
public class TCKimlikNoResult {
public boolean TCKimlikNoDogrulaResult;
}
}
Aşağıdaki hatayı alıyorum.
expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/soap/envelope/}soap:Envelope>@1:208 in java.io.InputStreamReader@892024f)
42
Görüntülenme
0 Beğeni