사용자 로그인을 위해 ksoap 웹 서비스를 사용하고 있습니다.하지만 사용자 이름과 비밀번호를 추가하면 메시지 로그인이 실패합니다 ... 어떻게 해결할 수 있습니까? username = adc 및 password = adc는 이미 완료되었습니다. 웹 서비스로그인 인증 실패
이 내 WebService 클래스입니다
public class DotNetWSActivity extends Activity {
static boolean errored = false;
Button b;
TextView tv;
EditText et ,pw;
boolean loginStatus;
ProgressBar pg;
String UserName ,Password;
String LoginAuthentication;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Name Text control
et = (EditText) findViewById(R.id.editText1);
pw = (EditText) findViewById(R.id.editText2);
//Display Text control
tv = (TextView) findViewById(R.id.tv_result);
//Button to trigger web service invocation
b = (Button) findViewById(R.id.button1);
//Display progress bar until web service invocation completes
pg = (ProgressBar) findViewById(R.id.progressBar1);
//Button Click Listener
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Check if Name text control is not empty
if (et.getText().length() != 0 && et.getText().toString() != "") {
if (pw.getText().length() != 0 && pw.getText().toString() != "") {
//Get the text control value
UserName = et.getText().toString();
Password =pw.getText().toString();
//Create instance for AsyncCallWS
AsyncCallWS task = new AsyncCallWS();
//Call execute
task.execute();
//If text control is empty
} else {
tv.setText("Please enter name");
}
}else {
tv.setText("Please enter password");
}
}
});
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
LoginAuthentication = WebService.invokeHelloWorldWS(UserName, Password,"LoginAuthentication");
return null;
}
protected void onPostExecute(Void result) {
// webservicePG.setVisibility(View.INVISIBLE);
Intent intObj = new Intent(DotNetWSActivity.this,dfdf.class);
//Error status is false
if(!errored){
//Based on Boolean value returned from WebService
if(loginStatus){
//Navigate to Home Screen
startActivity(intObj);
}else{
//Set Error message
tv.setText("Login Failed, try again");
}
//Error status is true
}else{
tv.setText("Error occured in invoking webservice");
}
//Re-initialize Error Status to False
errored = false;
}
protected void onPreExecute() {
pg.setVisibility(View.VISIBLE);
}
protected void onProgressUpdate(Void... values) {
}
}
}
MainActivity.class
public class WebService {
private static String NAMESPACE = "http://tempuri.org/";
private static String URL ="http://192.168.0.100/xandroid.asmx";
private static String SOAP_ACTION = "http://tempuri.org/";
public static String invokeHelloWorldWS(String UserName,String Password, String webMethName) {
String resTxt = null;
boolean loginStatus = false;
// Create request
SoapObject request = new SoapObject(NAMESPACE, webMethName);
// Property which holds input parameters
PropertyInfo celsiusPI = new PropertyInfo();
// Set Name
celsiusPI.setName("UserName");
// Set Value
celsiusPI.setValue(UserName);
celsiusPI.setName("Password");
// Set Value
celsiusPI.setValue(Password);
// Set dataType
celsiusPI.setType(String.class);
// Add the property to request object
request.addProperty(celsiusPI);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invole web service
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to fahren static variable
loginStatus = Boolean.parseBoolean(response.toString());
// resTxt = response.toString();
} catch (Exception e) {
e.printStackTrace();
resTxt = "Error occured";
}
return resTxt;
}
}
로그 캣 :
,07-24 12:13:47.121: W/System.err(1593): java.lang.NullPointerException
07-24 12:13:47.121: W/System.err(1593): at com.prgguru.android.WebService.invokeHelloWorldWS(WebService.java:50)
07-24 12:13:47.141: W/System.err(1593): at com.prgguru.android.DotNetWSActivity$AsyncCallWS.doInBackground(DotNetWSActivity.java:63)
07-24 12:13:47.151: W/System.err(1593): at com.prgguru.android.DotNetWSActivity$AsyncCallWS.doInBackground(DotNetWSActivity.java:1)
07-24 12:13:47.151: W/System.err(1593): at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-24 12:13:47.151: W/System.err(1593): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-24 12:13:47.151: W/System.err(1593): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-24 12:13:47.151: W/System.err(1593): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
07-24 12:13:47.151: W/System.err(1593): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-24 12:13:47.162: W/System.err(1593): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-24 12:13:47.162: W/System.err(1593): at java.lang.Thread.run(Thread.java:856)
어떤 줄이 WebService.java:50입니까? – Jens
webservice 클래스에 사용자 이름과 비밀번호 값을 가져 왔습니까? 먼저 확인하십시오. – prakash
예 웹 서비스 클래스에서 가치가 있습니다 –