Showing posts with label SOAP. Show all posts
Showing posts with label SOAP. Show all posts

Wednesday, June 29, 2011

Late Orders : Soap ASP.NET WebService & Android Ksoap2 Client

Here it is the source code and pictures from a sample application that exposes an ASP.NET 
SOAP webservice that is consumed in an Android Java Client ... 


How to load into Eclipse a project from Google.Code via subversion
How to add Android plugin to Eclipse Indigo


LateOrdersByZone extends ListActivity 


ViewsActivity : 
startActivity(new Intent(this, LateOrdersByZone.class));


Order[] allOrders;
Vector vectorOfStrings = new Vector();



int orderCount = vectorOfStrings.size();
String[] orderTimeStamps = new String[orderCount];
vectorOfStrings.copyInto(orderTimeStamps); 

setListAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_1 , orderTimeStamps));




http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/


Order
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/Order.java


LateOrdersByZone
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/src/net/learn2develop/AndroidViews/LateOrdersByZone.java


Copy1OfLateOrdersByZone


Copy2OfLateOrdersByZone


Copy3OfLateOrdersByZone






ASP.NET WebService : Orders2a.asmx 









what we want to do in a few years ...


Tuesday, March 29, 2011

SOAP , REST - Web Services - on Linux with Axis2

Working with Axis2: Making a Java Class into a Service

Exposing a Database as a Web Service

Understanding Axis2 Deployment Architecture


Inserting a New Person Object

Inserting a person object also can be done using a REST call. You need to pass the id, name, address, and the age to add a new person into the table. You can pass them as URL query parameters, as you can see below.
http://localhost:8080/axis2/services/DBSampleService/insertPerson?
id=130&name=Peter&address=No 5, Colombo, Sri Lanka&age=56
This will call the service and insert a new raw to the database. If you want to make sure that the new data in the database just lists all the people again, you can see the new person also in the DB.

 

Thursday, February 24, 2011

Return SalesAgents byName Or byZone

http://www.flickr.com/photos/24834074@N04/5472432292/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5471839947/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5472432212/sizes/l/in/photostream/
http://www.flickr.com/photos/24834074@N04/5471839801/sizes/l/in/photostream/



public class SalesAgent
{
    private string _name     = string.Empty;
    private string _surname  = string.Empty;
    private string _userID   = string.Empty;
    private string _zoneID   = string.Empty;
    private string _zoneName = string.Empty;
    private string _password = string.Empty;
   
    public SalesAgent(){}

    public string Name
    {
        get { return _name;  }
        set { _name = value; }
    }

    public string Surname
    {
        get { return _surname;  }
        set { _surname = value; }
    }

    public string UserID
    {
        get { return _userID;  }
        set { _userID = value; }
    }

    public string ZoneID
    {
        get { return _zoneID;  }
        set { _zoneID = value; }
    }

    public string ZoneName
    {
        get { return _zoneName; }
        set { _zoneName = value; }
    }
   
    public string Password
    {
        get { return _password;  }
        set { _password = value; }
    }

}


[WebMethod(Description = "Method to obtain SalesAgents by Zone or by Name")]
public SalesAgent[] ReturnSalesAgents(string theZone, string theAgent)
{

    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = " ";
    if ( theZone.Equals("") && theAgent.Equals("") ) {
    sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name,
                          dbo.PersoanaFizica.Prenume as Surname,  " +
                       " dbo.Utilizator.UtilizatorID as UserID, dbo.Utilizator.Parola as Password,
                         dbo.Utilizator.ZonaID as ZoneID, " +
                       " dbo.Zona.Denumire as ZoneName " +
                       " FROM dbo.PersoanaFizica , dbo.Zona , dbo.Utilizator  " +
                       " WHERE dbo.PersoanaFizica.PersoanaFizica_ID = dbo.Utilizator.UtilizatorID and " +
                       " dbo.Utilizator.ZonaID = dbo.Zona.Id " +
                       " ORDER BY dbo.PersoanaFizica.Nume, dbo.PersoanaFizica.Prenume ";
    }
    else if (theAgent.Equals(""))
    {
        sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name,
                            dbo.PersoanaFizica.Prenume as Surname,  " +
                           " dbo.Utilizator.UtilizatorID as UserID, dbo.Utilizator.Parola as Password,
                             dbo.Utilizator.ZonaID as ZoneID, " +
                           " dbo.Zona.Denumire as ZoneName" +
                           " FROM dbo.PersoanaFizica , dbo.Zona , dbo.Utilizator  " +
                           " WHERE dbo.PersoanaFizica.PersoanaFizica_ID = dbo.Utilizator.UtilizatorID and " +
                           " dbo.Utilizator.ZonaID = dbo.Zona.Id and " +
                           " dbo.Zona.Denumire LIKE" + "'%" + theZone + "%'" +
                           " ORDER BY dbo.PersoanaFizica.Nume, dbo.PersoanaFizica.Prenume ";
    }
    else {
        sqlSelect = " SELECT TOP (100) dbo.PersoanaFizica.Nume as Name,
                              dbo.PersoanaFizica.Prenume as Surname,  " +
                           " dbo.Utilizator.UtilizatorID as UserID, dbo.Utilizator.Parola as Password,
                              dbo.Utilizator.ZonaID as ZoneID, " +
                           " dbo.Zona.Denumire as ZoneName" +
                           " FROM dbo.PersoanaFizica , dbo.Zona , dbo.Utilizator  " +
                           " WHERE dbo.PersoanaFizica.PersoanaFizica_ID = dbo.Utilizator.UtilizatorID and " +
                           " dbo.Utilizator.ZonaID = dbo.Zona.Id and " +
                           " ( dbo.PersoanaFizica.Nume LIKE " + "'%" + theAgent + "%' or
                               dbo.PersoanaFizica.Prenume LIKE " + "'%" + theAgent + "%' )";
    }
   
   
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);
    dbConn.Close();
    List list = new List();
    foreach (DataRow row in dt.Rows)
    {
        SalesAgent target = new SalesAgent();
        target.Name = row["Name"].ToString();
        target.Surname = row["Surname"].ToString();
        target.ZoneID = row["ZoneID"].ToString();
        target.UserID = row["UserID"].ToString();
        target.Password = row["Password"].ToString();
        target.ZoneName = row["ZoneName"].ToString();
        list.Add(target);
    }
    return list.ToArray();
}

Tuesday, February 15, 2011

PersonPassport4.asmx - Simple webservice : INSERT UPDATE DELETE

Web Service C#.NET :
DB.SQL.TABLE as ARRAY
Android Client Consumer


From SOAP to WCF REST without LINQ : small and easy steps

PersonPassport2.asmx
http://code.google.com/p/jtelmon/source/browse/trunk/AndroidViews/PersonPassport2.asmx
http://jtelmon.googlecode.com/svn/trunk/AndroidViews/PersonPassport2.asmx

Building XML Web Services Using C# and ASP.NET



CREATE DATABASE minipassport 
GO 

CREATE TABLE Users ( 
UserName varchar (10) Primary Key NOT NULL , 
Name varchar (50) NOT NULL , 
EMail varchar (100) NOT NULL , 
Password varchar (10) NOT NULL 
) ON PRIMARY 
GO


http://www.flickr.com/photos/24834074@N04/5446222119/sizes/l/
http://www.flickr.com/photos/24834074@N04/5446222063/sizes/l/
http://www.flickr.com/photos/24834074@N04/5446839620/sizes/l/

http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport/src/passport/bimbim/in/MainLP2.java
http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport/src/passport/bimbim/in
http://code.google.com/p/jtelmon/source/browse/trunk/LocalPassport

<%@ WebService class = "PersonPassport2" Language="C#" Debug = "true"%>

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;


public class Person

{

    private string _name = string.Empty;
    private string _user_name = string.Empty;
    private string _eMaiL = string.Empty;
    private string _password = string.Empty;

  public Person() {}




    public string Name

    {

        get { return _name; }

        set { _name = value; }

    }

   
        public string Password

    {

        get { return _password; }

        set { _password = value; }

    }

   
   
    public string UserName

    {

        get { return _user_name; }

        set { _user_name = value; }

    }

    public string EMail

    {

        get { return _eMaiL; }

        set { _eMaiL = value; }

    }

        

}

public class PersonPassport2 : WebService
{
const string connStr = "server=localhost;uid=sa;pwd=kash;database=minipassport";

[WebMethod(Description = "Method to Authenticate Users")]
public bool Authenticate(string username, string password)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select password from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();

bool returnBool;
if (dbReader.Read())
{
if (dbReader[0].ToString()==password)
{
returnBool = true;
}
else
{
returnBool = false;
}
}
else
{
returnBool=false;
}
dbReader.Close();
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Add User")]
public bool AddUser(string username, string password, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "INSERT INTO users(username,password,name,email) values('" + username + "', '" + password + "', '" + name + "', '" + email + "');";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
returnBool=true;
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Delete User")]
public bool DeleteUser(string username)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "DELETE FROM users where username = '" + username +"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Edit User Information")]
public bool EditUser(string username, string name, string email)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET username = '" + username +"',name = '"+name+"',email= '"+email+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Change User Password")]
public bool ChangePassword(string username, string password)
{
bool returnBool = false;
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "UPDATE users SET password = '"+password+"';";
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
try
{
dbConn.Open();
if (dbCommand.ExecuteNonQuery()!=0)
{
returnBool=true;
}
}
catch
{
returnBool=false;
}
dbConn.Close();
return returnBool;
}

[WebMethod(Description = "Method to Obtain User Name")]
public string ReturnName(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select Name from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain User Email Address")]
public string ReturnEmail(string username)
{
SqlConnection dbConn = new SqlConnection(connStr);
string sqlStr = "Select email from users where username = '" + username + "';";
dbConn.Open();
SqlCommand dbCommand = new SqlCommand(sqlStr,dbConn);
SqlDataReader dbReader = dbCommand.ExecuteReader();
dbReader.Read();
string _name = dbReader[0].ToString();
dbReader.Close();
dbConn.Close();
return _name;
}

[WebMethod(Description = "Method to obtain All User Info")]
public DataSet ReturnAll()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataSet ds = new DataSet();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(ds, "users");
    dbConn.Close();
    return ds;
}

[WebMethod(Description = "Method to obtain All User Info")]
public Person[] ReturnArray()
{
    SqlConnection dbConn = new SqlConnection(connStr);
    dbConn.Open();
    string sqlSelect = "select * from users ";
    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, dbConn);
    DataTable dt = new DataTable();
    SqlCommand dbCommand = new SqlCommand(sqlSelect, dbConn);
    da.Fill(dt);   
    dbConn.Close();
    List list = new List();
    foreach(DataRow row in dt.Rows) {
        // Person target = Activator.CreateInstance();
        Person target = new Person();
        target.Name = row["Name"].ToString();
        target.UserName = row["UserName"].ToString();
        target.EMail = row["EMail"].ToString();
        target.Password = row["Password"].ToString();
        // DataColumnAttribute.Bind(row,target);
        list.Add(target);
    }
    return list.ToArray();
}


 [WebMethod]
    public Person GetSingle()
    {
        Person person = new Person();
        person.Name = "bimbim.in";
        //person.Age = 30;
        //person.Dob = new System.DateTime(1980, 01, 15);
        //person.Salary = 50000f;
        return person;
    }

[WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

}











Dumped Database can be downloaded at :
https://docs.google.com/leaf?id=0BzKVfKe--t_cYjAzOTk5YmEtNjk1ZS00ZTcxLWIzMDgtYTMwMTVlMTQwZDVi&hl=en_GB