//Enter this in your activity_main.xml file.....
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#EDEDED" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/image1"
android:layout_alignParentTop="true"
android:scaleType="fitStart"
android:src="@drawable/vijayfinal" />
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText1"
android:layout_alignParentLeft="true"
android:layout_marginTop="50dp"
android:src="@drawable/new4" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignLeft="@+id/TextView03"
android:layout_alignParentBottom="true"
android:background="#2B4372"
android:text="Sign In"
android:textColor="#ffffff"
android:textSize="25sp"
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText2"
android:layout_alignLeft="@+id/image1"
android:ems="10"
android:hint="UserName"
android:inputType="textPersonName"
android:layout_marginTop="36dp">
<requestFocus />
</EditText>
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="@+id/image1"
android:layout_below="@+id/image1"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:padding="5dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Dear Customer, for your login detail's kindly contact us on 0231-2610004...."
android:textColor="#FF0000"
android:textSize="15dp"
/>
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignLeft="@+id/editText1"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentRight="true"
android:text="Save Id"
android:layout_alignRight="@+id/editText1" />
</RelativeLayout>
package com.example.myproject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
//import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/CheckPassword";
private static final String OPERATION_NAME = "CheckPassword";// your webservice web method name
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://webservice.vijaytextilesgnr.com/Service.asmx/CheckPassword";
EditText edUser,edpass;
TextView txtResponse;
Button btSubmitt;
String strUser;
String strPass;
String strUserpwd;
String strResponse;
String strResponse1;
String strResponse2;
private static final ActionBar actionBar = null;
private TextView marqueeText;
private String message;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edUser=(EditText)findViewById(R.id.editText1);
edpass=(EditText)findViewById(R.id.editText2);
btSubmitt=(Button)findViewById(R.id.button1);
TextView tv = (TextView) this.findViewById(R.id.TextView03);
tv.setSelected(true);
btSubmitt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new checkWS().execute();
}
});
}
//new code For Database
private class checkWS extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "UserPass";
PublicClass.pusername = edUser.getText().toString();
PublicClass.ppass = edpass.getText().toString();
strUserpwd=PublicClass.pusername+":"+PublicClass.ppass;
request.addProperty(propertyInfo, strUserpwd);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE("http://webservice.vijaytextilesgnr.com/Service.asmx?op=CheckPassword");
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
//strResponse=response.toString();
//strResponse1=response.toString();
strResponse2=response.toString();
Log.e("",strResponse2);
}
catch(Exception e)
{
e.printStackTrace();
}
return strResponse2;
}
protected void onPostExecute(String unused)
{
// txtResponse.setText(strResponse);
if(strResponse2.equals("Yes"))
{
Intent i = new Intent(getApplicationContext(), Home.class);
startActivity(i);
}
else
{
Toast.makeText(MainActivity.this, "Login Unsuccessfully", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
//Enter this code in your "Manifest" file
//After This you must Internet Permission in mainfest file using this follwing line:-
<uses-permission android:name="android.permission.INTERNET" />
-:Best Of Luck:-

This helped a lot!
ReplyDeleteNow I can easily connect my android app to my web service very easily!
Couldn't find this code anywhere else on the web... Thanks again!
Thank you Amrut Sir..............
ReplyDelete