2014-07-24 3 views
0

사용자 로그인을 위해 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) 
+0

어떤 줄이 WebService.java:50입니까? – Jens

+0

webservice 클래스에 사용자 이름과 비밀번호 값을 가져 왔습니까? 먼저 확인하십시오. – prakash

+0

예 웹 서비스 클래스에서 가치가 있습니다 –

답변

0

당신의 doInBackground

LoginAuthentication = WebService.invokeHelloWorldWS(UserName, Password,"LoginAuthentication"); 

에서 일

몇 당신은 인스턴스화되지 않은 클래스의 메소드를 호출하고 있습니다. 내가 추천하는 것은 WebService 내부에 생성자를 생성하고 그 3 개의 매개 변수를 취한 다음 클래스에 getter를 가지고 resTxt을 반환하는 것입니다. 그런 다음 클래스에 전화가

WebService webservice = new WebService(UserName, Password,"LoginAuthentication"); 
String LoginAuthentication = webservice.getResTxt(); 

과 같을 것이다 또는 당신은 당신이 지금 가지고있는 형식을 유지를 주장하는 경우, 당신은 여전히 ​​처음 new WebService를 호출하여 클래스를 인스턴스화해야합니다.

invokeHelloWorldWS 메서드가 정적이기 때문에 지금 컴파일 오류가 발생하지 않는 유일한 이유는 ... 가능한 것부터 정적 인 이유가 없습니다.

또한 doInBackground에서 NULL을 onPostExecute로 전달 중입니다 ... 이유가 무엇입니까? onPostExecute에 대한 요점은 doInBackground에서 값을 가져 와서 그것으로 무언가를하는 것입니다.

+0

u pls 대답으로 내 코드를 수정할 수 있습니다 .... –

+0

stackoverflow의 요점은 당신에게 당신의 코드를 완전히 다시 작성하는 것이 아니라 귀하의 문제를 돕기위한 출발점이나 지침을 제공하는 것입니다. – memo