使用用户名和密码连接到Web服务

时间:2012-07-12 11:47:04

标签: android web-services

我是网络服务问题的新手。我想通过用户名和密码连接到网络服务器。我找到了一些解决方案如何连接和获得响应,但经过一些试验我没有成功。我得到了下面显示的一些错误。这是我的代码,你能帮帮我吗?

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

1 个答案:

答案 0 :(得分:1)

你需要获得正确版本的ksoap2 jar

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

  • 下载此jar并将其添加到classpath

修改 现在有一个更新的ksoap2 JAR

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

试试这个