如何在Android中创建登录页面。(使用kso​​ap2 web服务sharepoint)

时间:2012-08-31 04:22:39

标签: android web-services ksoap2

我是Android的新手。我试图创建登录页面,但总是出错。

我添加了ksoap2.java和权限INTERNET。

这是我的代码。

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;

    public class Main extends Activity {

    private final String NAMESPACE = "http://schemas.microsoft.com/sharepoint/soap/";
    private final String URL = "http://ipaddress/_vti_bin/authentication.asmx?WSDL";

    String username;
    String password;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button signin = (Button) findViewById(R.id.regsubmitbtn);
        signin.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                EditText etxt_user = (EditText) findViewById(R.id.usereditlog);
                username = etxt_user.getText().toString();
                EditText etxt_password = (EditText)  findViewById(R.id.pwdeditlog);
                password = etxt_password.getText().toString();
                Login(username,password);
            }
        });   
    }
    private void Login(String user, String pass) {   


        final String SOAP_ACTION = "http://schemas.microsoft.com/sharepoint/soap/Login";
        final String METHOD_NAME = "Login";     
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("username",user);
        request.addProperty("password",pass);
        SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true; 
        envelope.setOutputSoapObject(request);
        System.out.println(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            Intent i = new Intent(Main.this,List.class);
            startActivity(i);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

}

点击登录按钮时,必须更改为其他页面但是错误。

感谢您的帮助。


这是我的logcat on error.please help。

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
at com.app.jobrequest.Main.Login(Main.java:45)
at com.app.jobrequest.Main.access$0(Main.java:40)
at com.app.jobrequest.Main$1.onClick(Main.java:36)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.langreflect.Method.invokeNative(Native Method)
at java.land.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStrat.main(Native Method)

1 个答案:

答案 0 :(得分:0)

从您的网址中删除“?WSDL”。如果您仍有问题,请更新您的帖子,详细了解您收到的错误消息。

private final String URL = "http://ipaddress/_vti_bin/authentication.asmx";