2012-07-12 113 views
0

我是新的web服務問題。我想通過用戶名和密碼連接到網絡服務器。我發現了一些解決方案,如何連接並獲得響應,但經過一些試驗後,我失敗了。我正在開始下面顯示的一些錯誤。這是我的代碼,你可以幫我嗎?通過使用用戶名和密碼連接到webservice

package com.isoft.uploader; 

import java.util.ArrayList; 

import org.json.JSONArray; 
import org.json.JSONObject; 
import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransport; 

import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class UploaderActivity extends Activity 
{ 

//ArrayList<Response> WebData= new ArrayList<Response>(); 
public static final int SELECT_VIDEO=1; 
public static final String TAG="UploadActivity"; 
String path=""; 
final String NAMESPACE = "http://tempuri.org/"; 
final String SERVICEURL = "http://192.168.10.177/androidws/isandroidws.asmx"; 
final String METHOD_NAME1="OzelVeriAlanlariniGetir"; 
final String METHOD_NAME="KullaniciGiris"; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button enter=(Button)findViewById(R.id.Enter); 
    final EditText username=(EditText)findViewById(R.id.username); 
    final EditText password=(EditText)findViewById(R.id.password); 
    enter.setOnClickListener(new View.OnClickListener() 
    { 

     @Override 
     public void onClick(View arg0) 
     { 
      // TODO Auto-generated method stub 
      //request code for Webservice 
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
      //sending the username to the webservice 
      request.addProperty("kullaniciAdi",username.getText().toString()); 
      //sending the password to the webservice 
      request.addProperty("password",password.getText().toString()); 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.dotNet = true; 
      //Putting the request in an envelope 
      envelope.setOutputSoapObject(request); 
      HttpTransport transport = new HttpTransport(SERVICEURL); 
      try 
      { 
       transport.call("http://tempuri.org/"+METHOD_NAME, envelope); 
       //getting the response from the webservice 
       Boolean response = (Boolean) envelope.getResponse(); 
       if(response==true) 
       { 
        openGaleryVideo(); 
       }//end of if statement 

       else setContentView(R.layout.main); 

      }//end of try 
      catch(Exception exception) 
      { 
       exception.printStackTrace(); 
      }//end of catch 

     }//end of onClick method 
    });//end of OnclickListener method 
}//end of onCreate method 

public void openGaleryVideo() 
{ 
    Intent intent=new Intent(); 
    intent.setType("video/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(Intent.createChooser(intent, "Select Video"),SELECT_VIDEO); 
}//end of openGaleryVideo method 

public String getPath(Uri uri) 
{ 
    String[] projection = { MediaStore.Video.Media.DATA}; 
    Cursor cursor = managedQuery(uri, projection, null, null, null); 
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); 
    cursor.moveToFirst(); 
    return cursor.getString(column_index); 
}//end of getPath method 
}//end of main 

enter image description here

+0

你已經宣佈在AndroidManifest.xml所有的活動?另外,請檢查你的'UploaderActivity.java' - 第63行。看起來在那裏的'onClick'方法有問題。 – pixelscreen 2012-07-12 11:51:15

+0

這是因爲它onClick,他試圖連接到web服務! – silentw 2012-07-12 11:52:33

+0

是的我沒有任何問題,我認爲這是關於jar文件,但我不知道如何解決它。 – answer88 2012-07-12 11:54:15

回答

1

你需要得到ksoap2罐子

ksoap2-android-assembly-2.4-jar-with-dependencies.jar

  • 下載這個罐子的正確版本,並將其添加classpath中

編輯 現在有更新的ksoap2 JAR

ksoap2-android-assembly-2.6.5-jar-with-dependencies.jar

嘗試用這種

+0

對不起,但是當我嘗試這個項目無法找到HttpTransport類。另外,當我添加他們兩個,我得到'轉換爲Dalvik格式失敗,錯誤1' – answer88 2012-07-12 12:09:49

+0

@ answer88你嘗試過'HttpTransportSE'類從該JAR嗎? – sunil 2012-07-12 12:15:21

+0

現在它工作!非常感謝!但現在openGaleryVideo()方法不工作,因爲如果我變得真實,我需要開始選擇視頻。然而,屏幕並沒有改變:S – answer88 2012-07-12 12:24:41

相關問題