2013-02-16 104 views
-1

當我發送用戶名和密碼它發送給我一個false:publicKey和用戶名和密碼不連接Web服務,我不知道是否有任何問題在 http://mobilews.terra.net.lb/MobileService.asmx?op=authenticateLogin 用戶名是:mabyad 密碼是:大道Android:無法通過使用Ksoap2連接到Web服務

的MainActivity.java代碼

package com.kak; 

import android.os.Bundle; 
import android.os.StrictMode; 

import com.kak.R; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 
//import android.widget.Toast; 
//import android.view.View.OnClickListener; 
import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.transport.HttpTransportSE; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.serialization.SoapPrimitive; 
//import android.widget.TextView; 
//import android.app.ProgressDialog; 
//import android.os.AsyncTask; 


public class MainActivity extends Activity { 
    private final static String SOAP_NAMESPACE = "http://mobilews.terra.net.lb"; 

    private static final String SOAP_URL = "http://mobilews.terra.net.lb/MobileService.asmx"; 

    private static final String SOAP_ACTION = "http://tempuri.org/authenticateLogin"; 

    private static final String SOAP_METHOD_NAME = "authenticateLogin"; 
    //private PropertyInfo pi1; 


    Button button1; 
    EditText UserName; 
    EditText Password; 
    public String publicKey; 

    String tv; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     StrictMode.ThreadPolicy policy = 
       new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
     setContentView(R.layout.activity_main); 

     button1=(Button)findViewById(R.id.button1); 
     button1.setOnClickListener(new View.OnClickListener() 
     { 


      @Override 

      public void onClick(View v) 
      { 
       UserName=(EditText)findViewById(R.id.UserName); 
       Password = (EditText)findViewById(R.id.Password); 

       SoapObject request = new SoapObject(SOAP_NAMESPACE, SOAP_METHOD_NAME); 


      request.addProperty("userName", UserName.getText().toString()); 
       request.addProperty("password",Password.getText().toString()); 
       request.addProperty("publicKey", String.valueOf("[email protected]$M0bilePK54")); 


       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
       envelope.setOutputSoapObject(request); 
       envelope.dotNet = true; 


        HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_URL); 
        try{ 

        androidHttpTransport.call(SOAP_ACTION, envelope); 

        SoapPrimitive resultString = (SoapPrimitive)envelope.getResponse(); 



![android manifest Permissions][1]     
        SoapPrimitive resultInteger =(SoapPrimitive)envelope.getResponse(); 

        tv=resultInteger.toString(); 

        if (resultString!=null || resultInteger !=null) { 
         Toast.makeText(getBaseContext(),tv, 
           Toast.LENGTH_LONG).show(); 
        } 
        else { 
         Toast.makeText(getBaseContext(),"wrong", 
          Toast.LENGTH_LONG).show(); 
        } 

       }catch (Exception e) { 

         e.printStackTrace(); 

        } 
      } 
      }); 
     } 











    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 
} 
+0

謝謝你的任何信息 – 2013-02-16 20:46:38

+0

我需要知道我的問題在哪裏:S – 2013-02-16 23:24:27

回答

0

我用ksoap2-android-assembly-2.6.2-jar-with-dependencies.jar與此代碼的工作對我來說:

public class MainActivity extends Activity { 
    private final String URL = "http://mobilews.terra.net.lb/MobileService.asmx"; 
    private final String METHOD_NAME = "authenticateLogin"; 
    private final String NAMESPACE = "http://tempuri.org/"; 
    private final String SOAP_ACTION = NAMESPACE + METHOD_NAME; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     authenticateLogin("mabyad", "dori", "your_public_key"); 
    } 

    private void authenticateLogin(String userName, String passWord, String publicKey) { 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     request.addProperty("userName", userName); 
     request.addProperty("password", passWord); 
     request.addProperty("publicKey", passWord); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = true; 

     envelope.setOutputSoapObject(request); 

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
     androidHttpTransport.debug = true; 
     try { 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
      SoapObject response = (SoapObject) envelope.bodyIn; 

      boolean authenticateLoginResult = Boolean.parseBoolean(response.getPropertyAsString("authenticateLoginResult")); 
      int customerId = Integer.parseInt(response.getPropertyAsString("customerId")); 
      String errorMsg = response.getPropertyAsString("errorMsg"); 

      System.out.println("authenticateLoginResult :: " + authenticateLoginResult); 
      System.out.println("customerId :: " + customerId); 
      System.out.println("errorMsg :: " + errorMsg); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

,輸出是:

authenticateLoginResult ::假

客戶ID :: 0

ERRORMSG :: unauthirized方法的使用,無效的密鑰