1. 44210205028
EX No:1(a)
BANKING
DATE:
AIM:
To implement banking using .NET component.
ALGORITHM:
Creating the Component
Start Visual Studio .NET and open a new Class Library project – File -> New project. In the
New Project dialog box, name the project as ClassLibrary1.
Change the name of the class from Class1 to Component name.
Enter the Component code into the new class module. Include the following
functions:Getpass(), balenquiry(), withdraw(), deposit().
Compile this class as a DLL by clicking Build on the Debug menu.The DLL that results
from the build command is placed into the bin directory immediately.
To add a Database connection, click on Data -> Add data source and add a new connection.
Browse and select the database created in the MS Access.
Select the table and test the connection. If successful copy the connection string.
Creating the Application
Start Visual Studio; clickFile -> New project -> Visual C# -> Windows form application.
Set the Name property of the default Windows Form
Design the Form by placing controls and naming them.
You need to set a reference to the DLL so that this form will be able to consume the
components services.
Do this by following the steps below.
From the class menu click Add Reference.
Select the necessary DLL component from the browse menu.
Run the application
2. 44210205028
COMPONENT:
CLASS1.CS
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace ClassLibrary1
{
public class Class1
{
public int getpass(string n)
{
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopprobanking.accdb");
con.Open();
string str = "SELECT pass FROM probanking where cust=@var1";
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.Parameters.AddWithValue("@var1", n);
int ret=(int)cmd.ExecuteScalar();
if (ret != null)
{
return ret;
}
else
{
return 0;
}
}
public int withdrawl(int money, int num)
{
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopprobanking.accdb");
con.Open();
string str = "SELECT bal FROM probanking where number=@var1";
OleDbCommand cmd = new OleDbCommand(str, con);
3. 44210205028
cmd.Parameters.AddWithValue("@var1", num);
int ret = (int)cmd.ExecuteScalar();
int tot = ret - money;
con.Close();
OleDbConnection coni = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopprobanking.accdb");
coni.Open();
string str1 = "UPDATE probanking SET bal="+tot+" "+" WHERE number="+num;
OleDbCommand cmd1 = new OleDbCommand(str1, coni);
cmd1.ExecuteNonQuery();
// cmd.Parameters.AddWithValue("@var2", tot);
coni.Close();
return tot;
}
public int balenquriy(int acc)
{
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopprobanking.accdb");
con.Open();
string str = "SELECT bal FROM probanking where number="+acc;
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.Parameters.AddWithValue("@var1", acc);
int ret = (int)cmd.ExecuteScalar();
return ret;
}
public int deposit(int money, int num)
{
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopprobanking.accdb");
con.Open();
string str = "SELECT bal FROM probanking where number=@var1";
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.Parameters.AddWithValue("@var1", num);
int ret = (int)cmd.ExecuteScalar();
int tot = ret + money;
4. 44210205028
string str1 = "UPDATE probanking SET bal="+tot+" "+"WHERE number="+num;
OleDbCommand cmd1 = new OleDbCommand(str1, con);
int r=(int) cmd1.ExecuteNonQuery();
return tot;
}
}
}
APPLICATION CODE:
FORM1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;
namespace probanking
{
public partial class Form1 : Form
{
Class1 obj = new Class1();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string name = textBox1.Text;
string pass = textBox2.Text;
int rer = int.Parse(pass);
int ret = obj.getpass(name);
if (ret==rer)
{
5. 44210205028
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
else
{
MessageBox.Show("invalid password");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
FORM2.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;
namespace probanking
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Show();
6. 44210205028
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
Form4 f4 = new Form4();
f4.Show();
this.Hide();
}
private void button3_Click(object sender, EventArgs e)
{
Form5 f5 = new Form5();
f5.Show();
this.Hide();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
FORM3.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;
namespace probanking
{
public partial class Form3 : Form
{
Class1 obj = new Class1();
public Form3()
{
InitializeComponent();
}
7. 44210205028
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string num = textBox1.Text;
string acc = textBox2.Text;
int account = int.Parse(acc);
int number = int.Parse(num);
int retur = obj.withdrawl(account, number);
MessageBox.Show("Your Balance is " + retur);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
}
FORM4.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
8. 44210205028
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;
namespace probanking
{
public partial class Form4 : Form
{
Class1 obj = new Class1();
public Form4()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string num = textBox1.Text;
string acc = textBox2.Text;
int account = int.Parse(acc);
int number = int.Parse(num);
int retur = obj.deposit(account, number);
MessageBox.Show("Current Balance is " + retur);
}
private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
9. 44210205028
FORM5.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;
namespace probanking
{
public partial class Form5 : Form
{
Class1 obj = new Class1();
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string acc = textBox1.Text;
int acc1 = int.Parse(acc);
int ret=obj.balenquriy(acc1);
textBox2.Text = Convert.ToString(ret);
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
}
18. 44210205028
EX No:1(b)
ONLINE COURSE REGISTRATION
DATE:
AIM:
To implement course registration using .NET component.
ALGORITHM:
Creating the Component
Start Visual Studio .NET and open a new Class Library project, File -> New project. In the
New Project dialog box, name the project classLibrary4.
Change the name of the class from Class1 to Component name.
Enter the Component code into the new class module. Include the following functions:
func(), ret().
Compile this class as a DLL by clicking Build on the Debug menu.The DLL that results
from the build command is placed into the bin directory immediately.
To add a Database connection, click on Data -> Add data source and add a new connection.
Browse and select the database created in the MS Access.
Select the table and test the connection. If successful copy the connection string.
Creating the Application
Start Visual Studio Start Visual Studio; clickFile -> New project -> Visual C# -> Windows
form application.
Set the Name property of the default Windows Form
Design the Form by placing controls and naming them.
You need to set a reference to the DLL so that this form will be able to consume the
components services.
Do this by following the steps below.
From the class menu click Add Reference.
Select the necessary DLL component from the browse menu.
Run the application
19. 44210205028
COMPONENT CODE:
CLASS1.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace ClassLibrary4
{
public class Class1
{
OleDbConnection conn = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopresult.accdb");
DataTable dt = new DataTable();
public int func(int a, int b)
{
if (a >= 75 && b >= 18)
return 1;
else return 0;
}
public DataTable ret(String query)
{
try
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(query,conn);
OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
dt.Clear();
adp.Fill(dt);
}
catch
{
}
finally
{
conn.Close();
}
return dt;
}
}
}
20. 44210205028
APPLICATION CODE:
FORM1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace olc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
}
FORM2.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace olc
{
21. 44210205028
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
Form4 f4 = new Form4();
f4.Show();
this.Hide();
}
}
}
FORM3.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace olc
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
22. 44210205028
// TODO: This line of code loads data into the 'studentDataSet.UG' table. You can move,
or remove it, as needed.
this.uGTableAdapter.Fill(this.studentDataSet.UG);
}
private void button1_Click(object sender, EventArgs e)
{
Form5 f5 = new Form5();
f5.Show();
this.Hide();
}
}
}
FORM4.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace olc
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'studentDataSet1.PG' table. You can move,
or remove it, as needed.
this.pGTableAdapter.Fill(this.studentDataSet1.PG);
}
private void button1_Click(object sender, EventArgs e)
{
Form5 f5 = new Form5();
23. 44210205028
f5.Show();
this.Hide();
}
}
}
FORM5.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using ClassLibrary4;
namespace olc
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Class1 c1 = new Class1();
Form5 f5 = new Form5();
Form6 f6 = new Form6();
String marks = textBox5.Text;
String age = textBox6.Text;
String id = textBox2.Text;
String name= textBox3.Text;
String email= textBox4.Text;
int m = int.Parse(marks);
int a = int.Parse(age);
24. 44210205028
int z = c1.func(m, a);
if (z == 1)
{
this.Hide();
OleDbConnection conn = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopresult.accdb");
conn.Open();
string strquery = "INSERT INTO res VALUES ('" + id + "', '" + name + "', '" + email +
"','"+marks +"','"+age+"');";
OleDbCommand cmd = new OleDbCommand(strquery, conn);
cmd.ExecuteNonQuery();
f6.Show();
this.Hide();
}
else
{
MessageBox.Show("Not eligible");
}
}
}
}
FORM6.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace olc
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
25. 44210205028
}
private void button1_Click(object sender, EventArgs e)
{
Form7 f7 = new Form7();
f7.Show();
this.Hide();
}
}
}
FORM7.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
using ClassLibrary4;
namespace olc
{
public partial class Form7 : Form
{
Class1 obj = new Class1();
public Form7()
{
InitializeComponent();
}
private void Form7_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = obj.ret("SELECT * FROM res");
}
}
}
35. 44210205028
EX No:1(c)
ORDER PROCESSING
DATE:
AIM:
To implement order processing using .NET component.
ALGORITHM:
Creating the Component
Start Visual Studio .NET and open a new Class Library project, File -> New project. In the
New Project dialog box, name the project ClassLibrary2.
Change the name of the class from Class1 to Component name.
Enter the Component code into the new class module. Include the following functions: ret(),
pay(), insertin(), change().
Compile this class as a DLL by clicking Build on the Debug menu.The DLL that results
from the build command is placed into the bin directory immediately.
To add a Database connection, click on Data -> Add data source and add a new connection.
Browse and select the database created in the MS Access.
Select the table and test the connection. If successful copy the connection string.
Creating the Application
Start Visual Studio; clickFile -> New project -> Visual C# -> Windows form application.
Set the Name property of the default Windows Form
Design the Form by placing controls and naming them.
You need to set a reference to the DLL so that this form will be able to consume the
components services.
Do this by following the steps below.
From the class menu click Add Reference.
Select the necessary DLL component from the browse menu.
Run the application
36. 44210205028
COMPONENT CODE:
CLASS1.CS
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace ClassLibrary2
{
public class Class1
{
static int isbn;
public void search(int num)
{
isbn = num;
}
public int ret()
{
int sa = isbn;
return sa;
}
public int pay(int isb, int bo)
{
OleDbConnection conz = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopFinalproprocess.accdb");
conz.Open();
string an = "SELECT quantity FROM proprocess where isbn=@var2";
OleDbCommand cmd1 = new OleDbCommand(an, conz);
cmd1.Parameters.AddWithValue("@var2", isb);
int are = (int)cmd1.ExecuteScalar();
if (are < bo)
{
return 0;
}
else
{
37. 44210205028
string ant = "SELECT cost FROM proprocess where isbn=@var2";
OleDbCommand cmd2 = new OleDbCommand(ant, conz);
cmd2.Parameters.AddWithValue("@var2", isb);
int arec = (int)cmd2.ExecuteScalar();
return arec;
}
}
public void insertin(string cnam, int number, int amount)
{
OleDbConnection conz = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopFinalproprocess.accdb");
conz.Open();
string an = "INSERT INTO proinvoice VALUES ('" + cnam + "', " + amount + ", " +
number + ")";
OleDbCommand cmd1 = new OleDbCommand(an, conz);
cmd1.ExecuteNonQuery();
}
public void change(int num)
{
int isb = isbn;
OleDbConnection conz = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopFinalproprocess.accdb");
conz.Open();
string an = "SELECT quantity FROM proprocess where isbn=@var2";
OleDbCommand cmd1 = new OleDbCommand(an, conz);
cmd1.Parameters.AddWithValue("@var2", isb);
int are = (int)cmd1.ExecuteScalar();
int tot = are - num;
string str = "UPDATE proprocess SET quantity=" + tot + " " + "WHERE isbn=" + isb;
OleDbCommand cmd = new OleDbCommand(str, conz);
cmd.ExecuteNonQuery();
}
}
}
38. 44210205028
APPLICATION CODE:
FORM1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace proprocess
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
FORM2.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
39. 44210205028
using System.Windows.Forms;
using ClassLibrary2;
namespace proprocess
{
public partial class Form2 : Form
{
Class1 obj = new Class1();
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string num = textBox1.Text;
int num1 = int.Parse(num);
obj.search(num1);
Form3 f3 = new Form3();
f3.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
FORM3.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using ClassLibrary2;
40. 44210205028
namespace proprocess
{
public partial class Form3 : Form
{
Class1 obj = new Class1();
public Form3()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Form4 f4 = new Form4();
f4.Show();
this.Hide();
}
private void Form3_Load(object sender, EventArgs e)
{
int num1 = obj.ret();
OleDbConnection con = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Documents and
SettingsstudentDesktopFinalproprocess.accdb");
con.Open();
string str = "SELECT * FROM proprocess where isbn=@var1";
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.Parameters.AddWithValue("@var1", num1);
OleDbDataReader re;
re = cmd.ExecuteReader();
41. 44210205028
if (re.Read())
{
textBox1.Text = (re[0].ToString());
textBox2.Text = (re[2].ToString());
textBox3.Text = (re[1].ToString());
textBox4.Text = (re[4].ToString());
textBox5.Text = (re[3].ToString());
}
else
{
MessageBox.Show("Failed");
}
}
}
}
FORM4.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary2;
namespace proprocess
{
public partial class Form4 : Form
{
Class1 obj = new Class1();
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string unit = textBox2.Text;
int unitn = int.Parse(unit);
int isbn = obj.ret();
int retm=obj.pay(isbn, unitn);
42. 44210205028
if (retm == 0)
{
MessageBox.Show("Units not available");
}
else
{
int tot = retm * unitn;
string temp = Convert.ToString(tot);
textBox3.Text = temp;
}
}
private void button3_Click(object sender, EventArgs e)
{
string nu = textBox2.Text;
int number = int.Parse(nu);
obj.change(number);
Form5 f5 = new Form5();
f5.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
FORM5.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary2;
43. 44210205028
namespace proprocess
{
public partial class Form5 : Form
{
Class1 obj = new Class1();
public Form5()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string cname = textBox1.Text;
int num = int.Parse(textBox2.Text);
int amt = int.Parse(textBox3.Text);
obj.insertin(cname, num, amt);
Form6 f6 = new Form6();
f6.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
52. 44210205028
EX No:1(e)
CALCULATOR
DATE:
AIM:
To implement calculator using .NET component.
ALGORITHM:
Creating the Component
Start Visual Studio .NET and open a new Class Library project, File -> New project. In the
New Project dialog box, name the project calclogic.
Change the name of the class from Class1 to Component name.
Enter the Component code into the new class module. Include the following functions:
add(). Sub(), mul(), div(), sin(), cos(), tan(), dot(), sqrt(), square(), cube(), log().
Compile this class as a DLL by clicking Build on the Debug menu.The DLL that results
from the build command is placed into the bin directory immediately.
To add a Database connection, click on Data -> Add data source and add a new connection.
Browse and select the database created in the MS Access.
Select the table and test the connection. If successful copy the connection string.
Creating the Application
Start Visual Studio; clickFile -> New project -> Visual C# -> Windows form application.
Set the Name property of the default Windows Form
Design the Form by placing controls and naming them.
You need to set a reference to the DLL so that this form will be able to consume the
components services.
Do this by following the steps below.
From the class menu click Add Reference.
Select the necessary DLL component from the browse menu.
Run the application
53. 44210205028
COMPONENT:
CLASS1.CS
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace calclogic
{
public class Class1
{
public float add(float a, float b)
{
return a + b;
}
public float sub(float a, float b)
{
return a - b;
}
public float mul(float a, float b)
{
return a * b;
}
public float div(float a, float b)
{
return a/b;
}
public double log(double a)
{
return Math.Log(a);
}
public double tan(double a)
{
return Math.Tan(a);
}
public double cos(double a)
{
return Math.Cos(a);
}
public double sin(double a)
{
54. 44210205028
return Math.Sin(a);
}
public string dot()
{
return ".";
}
public double sqrt(double a)
{
return Math.Sqrt(a);
}
public double square(double a)
{
return Math.Pow(a, 2);
}
public double cube(double a)
{
return Math.Pow(a, 3);
}
}
}
FORM1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using calclogic;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
Class1 obj = new Class1();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text);
55. 44210205028
float b = float.Parse(textBox2.Text);
float c = obj.add(a, b);
textBox3.Text = c.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text);
float b = float.Parse(textBox2.Text);
float c = obj.sub(a, b);
textBox3.Text = c.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text);
float b = float.Parse(textBox2.Text);
float c = obj.mul(a, b);
textBox3.Text = c.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text);
float b = float.Parse(textBox2.Text);
float c = obj.div(a, b);
textBox3.Text = c.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
double c = obj.log(a);
textBox3.Text = c.ToString();
}
private void button6_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
double c = obj.sin(a);
textBox3.Text = c.ToString();
}
private void button7_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
56. 44210205028
double c = obj.cos(a);
textBox3.Text = c.ToString();
}
private void button8_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
double c = obj.tan(a);
textBox3.Text = c.ToString();
}
private void button11_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
double c = obj.sqrt(a);
textBox3.Text = c.ToString();
}
private void button12_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
double c = obj.square(a);
textBox3.Text = c.ToString();
}
private void button9_Click(object sender, EventArgs e)
{
double a = double.Parse(textBox1.Text);
double c = obj.cube(a);
textBox3.Text = c.ToString();
}
}
}
58. 44210205028
EX No: 2
INVOKE .NET COMPONENT AS A WEB SERVICE
DATE:
AIM:
To invoke a .NET component as a web service.
ALGORITHM:
Create a class library.
Add the appropriate sample codes to the class.
Modify the properties of the class library, Right click -> class library name -> properties
Assembly information. Make Assembly COM visible.Build -> Register for COM interop
Build the project and the dll will be created.
Create a new asmx project.
Right click on the project and click add reference. Then browse the appropriate dll and
click ok.
Add the code in the asmx file.
Create a new website type ASP.NET in c# code and do the appropriate form designing.
Add the corresponding web reference Right click -> Add Web Reference. Copy and paste
the WSDL link generated from the Web Service project.
Insert the code on the button click operation.
Build the website and click on Debug tab and start without Debugging. Now the project
will invoke the web service and in turn invoke the dll.
59. 44210205028
CLASS LIBRARY:
Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public double celtofar(double c)
{
double a;
a = (1.8 * c) + 32;
return a;
}
public double fartocel(double f)
{
double a;
a = 0.55 * (f - 32);
return a;
}
}
}
Service1.asmx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
60. 44210205028
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the
following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public double ctof(double c)
{
ClassLibrary1.Class1 obj = new ClassLibrary1.Class1();
return obj.celtofar(c);
}
[WebMethod]
public double ftoc(double f)
{
ClassLibrary1.Class1 obj = new ClassLibrary1.Class1();
return obj.fartocel(f);
}
}
}
WEB APPLICATION :
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
61. 44210205028
protected void Button1_Click1(object sender, EventArgs e)
{
double a, b;
a = Double.Parse(TextBox1.Text);
localhost.Service1 ws = new localhost.Service1();
b = ws.ctof(a);
TextBox2.Text = b.ToString();
}
protected void Button2_Click1(object sender, EventArgs e)
{
double a, b;
a = Double.Parse(TextBox3.Text);
localhost.Service1 ws = new localhost.Service1();
b = ws.ftoc(a);
TextBox4.Text = b.ToString();
}
}
}
63. 44210205028
EX No: 3(a) DEVELOP COMPONENTS USING EJB COMPONENT TECHNOLOGY
DATE:
ORDER PROCESSING
AIM:
To develop an Order Processing component using EJB component as a web service.
ALGORITHM:
Step 1: Go to NetBeans IDE-> File -> New Project -> Java EE -> EJB Module -> Next and
name the project as “orderprocessing” -> Next -> Finish.
Step 2: Create new web service
a. Right Click the created project name -> New -> Web Service -> Give name for the
web service and package -> Finish.
b. A new folder named “web services” will be created under the project folder. Inside
that, new web services will be created.
Step 3: Creating function for web service
Under the web services folder, right click the web service created -> Add operation.
*Give the appropriate name for the operation
*Select the return type of the function
*Adding parameters:
Click Add -> Give name of the parameter and their data type.
Click OK.
Step 4: Write the required operation inside the function and also see to the return type matches.
Write the required coding and save the file.
______________________________________________________________________________
/* Sample Code */
@WebMethod(operationName=”subtotal”)
Public double subtotal(@WebParam(name= “id”) int id, @WebParam(name= “quant”)
int quantity)
______________________________________________________________________________
Step 5: Right Click on the webservice -> Add Operation -> choose the operation name and
return type.
Step 6:
a. Right Click the project -> Deploy
64. 44210205028
b.In the web service folder, right click on the web service -> Test web service.
Step 7: Get into NetBeans IDE, go to File -> New Project -> Java -> Web Application
Give the name of the project as “clientpro”.
Step 8: Create a Home Page to receive sequence.
Step 9: Create component necessary to invoke the service from the client
a.Right click “clientpro” -> new -> WebServiceClient
b. Click Browse and select the required service.
Step 10: Build and Run the Web Application.
PROGRAM:
ORDERSERVER.JAVA
package pack;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
import java.sql.*;
@WebService(serviceName = "orderserver")
@Stateless()
public class orderserver {
/** This is a sample web service operation */
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
@WebMethod(operationName = "subTotal")
public double subTotal(@WebParam(name = "id") int id, @WebParam(name = "quantity") int
quantity) {
double price,total=0;
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con=
DriverManager.getConnection("jdbc:derby://localhost:1527/orderdb","student","student");
Statement stmt=con.createStatement();
ResultSet rs= stmt.executeQuery("select * from APP.LIST where id="+id);
while(rs.next())
72. 44210205028
EX No: 3(b)
PAYMENT PROCESSING
DATE:
AIM:
To develop a Payment Processing component using EJB component as a web service.
ALGORITHM:
Step 1: Go to NetBeans IDE-> File -> New Project -> Java EE -> EJB Module -> Next and
name the project
as “paymentprocessing” ->
Next -> Finish.
Step 2: Create new web service
a. Right Click the created project name -> New -> Web Service -> Give name for the
web service and package -> Finish.
b. A new folder named “web services” will be created under the project folder. Inside
that, new web services will be created.
Step 3: Creating function for web service
Under the web services folder, right click the web service created -> Add operation.
*Give the appropriate name for the operation
*Select the return type of the function
*Adding parameters:
Click Add -> Give name of the parameter and their data type.
Click OK.
Step 4: Write the required operation inside the function and also see to the return type matches.
Write the required coding and save the file.
/* Sample Code */
73. 44210205028
__________________________________________________________________________
@WebMethod(operationName=”getBalance”)
Public int getBalance(@WebParam(name= “ino”) int ino)
__________________________________________________________________________
Step 5: Right Click on the webservice -> Add Operation -> choose the operation name and
return type.
Step 6: a.
Right Click the project -> Deploy
c. In the web service folder, right click on the web service -> Test web service.
Step 7: Get into NetBeans IDE, go to File -> New Project -> Java -> Web Application
Give the name of the project as “clientpayment”.
Step 8: Create a Home Page to receive sequence.
Step 9: Create component necessary to invoke the service from the client
a. Right click “clientpayment” -> new -> WebServiceClient
b. Click Browse and select the required service.
Step 10: Build and Run the Web Application.
PROGRAM:
PaymentServer:
package pack;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
74. 44210205028
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(serviceName="payws")
@Stateless()
public class payws
{
int bal,i;
Date d=new Date();
String a="";
@WebMethod(operationName="getCDate")
public Date getCDate(@WebParam(name="ino")int ino)
{
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/paydb","student","student");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from APP.PAYM where INVOICE_NO="+ino);
while(rs.next())
{
d=rs.getDate("CREATED_ON");
}
}
catch(Exception e)
{
75. 44210205028
}
return d;
}
@WebMethod(operationName="getFDate")
public Date getFDate(@WebParam(name="ino")int ino)
{
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/paydb","student","student");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from APP.PAYM where INVOICE_NO="+ino);
while(rs.next())
{
d=rs.getDate("COMPLETED_ON");
}
}
catch(Exception e)
{
}
return d;
}
@WebMethod(operationName="getBalance")
public int getBalance(@WebParam(name="ino")int ino)
{
try
{
89. 44210205028
EX No: 3(c)
CALCULATOR
DATE:
AIM:
To develop Calculator component using EJB component as a web service.
ALGORITHM:
Step 1: Go to NetBeans IDE-> File -> New Project -> Java EE -> EJB Module -> Next and
name the projectas “Calculator” -> Next -> Finish.
Step 2: Create new web service
d. Right Click the created project name -> New -> Web Service -> Give name for the
web service and package -> Finish.
e. A new folder named “web services” will be created under the project folder. Inside
that, new web services will be created.
Step 3: Creating function for web service
Under the web services folder, right click the web service created -> Add operation.
*Give the appropriate name for the operation
*Select the return type of the function
*Adding parameters:
Click Add -> Give name of the parameter and their data type.
Click OK.
Step 4: Write the required operation inside the function and also see to the return type matches.
Write the required coding and save the file.
* Sample Code
90. 44210205028
________________________________________________________________________
@WebMethod(operationName=”getBalance”)
Public int getBalance(@WebParam(name= “ino”) int ino)
__________________________________________________________________________
Step 5: Right Click on the webservice -> Add Operation -> choose the operation name and
return type.
Step 6: a.
Right Click the project -> Deploy
f. In the web service folder, right click on the web service -> Test web service.
Step 7: Get into NetBeans IDE, go to File -> New Project -> Java -> Web Application
Give the name of the project as “clientcalc”.
Step 8: Create a Home Page to receive sequence.
Step 9: Create component necessary to invoke the service from the client
c. Right click “clientcalc” -> new -> WebServiceClient
d. Click Browse and select the required service.
Step 10: Build and Run the Web Application.
PROGRAM:
Calcservice.java
package calpack;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
/**
*
* @author student
91. 44210205028
*/
@WebService(serviceName = "Calcservice")
@Stateless()
public class Calcservice {
/** This is a sample web service operation */
/**
* Web service operation
*/
@WebMethod(operationName = "add")
public int add(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
//TODO write your implementation code here:
return a+b;
}
/**
* Web service operation
*/
@WebMethod(operationName = "sub")
public int sub(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
//TODO write your implementation code here:
return a-b;
}
/**
* Web service operation
*/
@WebMethod(operationName = "mult")
public int mult(@WebParam(name = "a") int a, @WebParam(name = "b") int b) {
92. 44210205028
//TODO write your implementation code here:
return a*b;
}
/**
* Web service operation
*/
@WebMethod(operationName = "divide")
public double divide(@WebParam(name = "a") double a, @WebParam(name = "b") double b)
{
//TODO write your implementation code here:
return a/b;
}
}
INDEX.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>
Calculator
</h1>
<%
try
{
93. 44210205028
calpack.Calcservice_Service service=new calpack.Calcservice_Service();
calpack.Calcservice port=service.getCalcservicePort();
int a=0;
int b=0;
int result1=port.add(5, 6);
int result2=port.mult(5, 6);
int result3=port.sub(6, 5);
double result4=port.divide(85.5, 5.5);
out.println("<b>Sum</b>
="+result1);
out.println("<br><b>Difference</b>="+result3);
out.println("<br><b>Product</b> ="+result2);
out.println("<br><b>Quotient</b> ="+result4);
}
catch(Exception e)
{
}
%>
</body>
</html>
97. 44210205028
EX No: 3(d)
STUDENT MARKLIST
DATE:
AIM:
To develop student marklistcomponent using EJB component as a web service.
ALGORITHM:
Step 1: Go to NetBeans IDE-> File -> New Project -> Java EE -> EJB Module -> Next and
name the project as “marklistprocessing” -> Next -> Finish.
Step 2: Create new web service
g. Right Click the created project name -> New -> Web Service -> Give name for the
web service and package -> Finish.
h. A new folder named “web services” will be created under the project folder. Inside
that, new web services will be created.
Step 3: Creating function for web service
Under the web services folder, right click the web service created -> Add operation.
*Give the appropriate name for the operation
*Select the return type of the function
*Adding parameters:
Click Add -> Give name of the parameter and their data type.
Click OK.
Step 4: Write the required operation inside the function and also see to the return type matches.
Write the required coding and save the file.
_______________________________________________________________________
/* Sample Code */
@WebMethod(operationName=”getName”)
Public String getName(@WebParam(name= “no”) int no)
________________________________________________________________________
98. 44210205028
Step 5: Right Click on the webservice -> Add Operation -> choose the operation name and
return type.
Step 6: a. Right Click the project -> Deploy
b. In the web service folder, right click on the web service -> Test web service.
Step 7: Get into NetBeans IDE, go to File -> New Project -> Java -> Web Application
Give the name of the project as “clientmarklist”.
Step 8: Create a Home Page to receive sequence.
Step 9: Create component necessary to invoke the service from the client
e. Right click “clientmarklist” -> new -> WebServiceClient
f. Click Browse and select the required service.
Step 10: Build and Run the Web Application.
PROGRAM:
SERVER:
package pack;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
import java.sql.*;
@WebService(serviceName = "mlws")
@Stateless()
public class mlws {
@WebMethod(operationName = "getdetails")
public double[] getdetails(@WebParam(name = "num") int num) {
double a1[] =new double[6];
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
c=DriverManager.getConnection("jdbc:derby://localhost:1527/studentdb","student","student");
Statement st=c.createStatement();
99. 44210205028
ResultSet rs=st.executeQuery("select * from APP.STUDENT where REG_NO="+num);
while(rs.next())
{
a1[0]=rs.getDouble("MATHS");
a1[1]=rs.getDouble("PHYSICS");
a1[2]=rs.getDouble("CHEMSITRY");
a1[3]=rs.getDouble("COMPUTER_SCIENCE");
a1[4]=a1[0]+a1[1]+a1[2]+a1[3];
a1[5]=a1[4]/4;
}
}
catch(Exception ex)
{
}
return a1;
}
@WebMethod(operationName = "getName")
public String getName(@WebParam(name = "no")int no) {
String name="";
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
c=DriverManager.getConnection("jdbc:derby://localhost:1527/studentdb","student","student");
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from APP.STUDENT where
REG_NO="+no+"");
while(rs.next())
{
name=rs.getString("NAME");
}
}
catch(Exception ex)
{}
return name;
}
@WebMethod(operationName = "getNo")
public int getNo()
{
int no=0;
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
105. 44210205028
EX No: 3(d) DEVELOP COMPONENTS USING EJB COMPONENT TECHNOLOGY
DATE:
PAYROLL PROCESSING
AIM:
To develop payroll processing component using EJB component as a web service.
ALGORITHM:
Step 1: Go to NetBeans IDE-> File -> New Project -> Java EE -> EJB Module -> Next and
name the project as “payroll” -> Next -> Finish.
Step 2: Create new web service
i. Right Click the created project name -> New -> Web Service -> Give name for the
web service and package -> Finish.
j. A new folder named “web services” will be created under the project folder. Inside
that, new web services will be created.
Step 3: Creating function for web service
Under the web services folder, right click the web service created -> Add operation.
*Give the appropriate name for the operation
*Select the return type of the function
*Adding parameters:
Click Add -> Give name of the parameter and their data type.
Click OK.
Step 4: Write the required operation inside the function and also see to the return type matches.
Write the required coding and save the file.
_______________________________________________________________________
/* Sample Code */
@WebMethod(operationName=”getName”)
Public String getName(@WebParam(name= “no”) int no)
________________________________________________________________________
106. 44210205028
Step 5: Right Click on the webservice -> Add Operation -> choose the operation name and
return type.
Step 6: a. Right Click the project -> Deploy
b. In the web service folder, right click on the web service -> Test web service.
Step 7: Get into NetBeans IDE, go to File -> New Project -> Java -> Web Application
Give the name of the project as “clientpayroll”.
Step 8: Create a Home Page to receive sequence.
Step 9: Create component necessary to invoke the service from the client
g. Right click “clientpayroll” -> new -> WebServiceClient
h. Click Browse and select the required service.
Step 10: Build and Run the Web Application.
PROGRAM:
SERVER:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pckg;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
/**
*
* @author student
*/
@WebService(serviceName = "payservice")
@Stateless()
public class payservice {
@WebMethod(operationName="calculate")
public double[] calculate(@WebParam(name="basic")double
basic,@WebParam(name="ded")double ded)
112. 44210205028
EX No: 4
DATE:
INVOKE EJB COMPONENTS AS WEB SERVICE
TICKET RESERVATION
AIM:
To develop Ticket Reservation component using EJB component as a web service.
ALGORITHM:
Step 1: Go to NetBeans IDE-> File -> New Project -> Java EE -> EJB Module -> Next and
name the project as “ticket” -> Next -> Finish.
Step 2: Create new web service
a. Right Click the created project name -> New -> Web Service -> Give name for the
web service and package -> Finish.
b. A new folder named “web services” will be created under the project folder. Inside
that, new web services will be created.
Step 3: Creating function for web service
Under the web services folder, right click the web service created -> Add operation.
*Give the appropriate name for the operation
*Select the return type of the function
*Adding parameters:
Click Add -> Give name of the parameter and their data type.
Click OK.
Step 4: Write the required operation inside the function and also see to the return type matches.
Write the required coding and save the file.
-----------------------------------------------------------------------------------------------------------/* Sample Code */
@WebMethod(operationName=”getID”)
Public int getID(@WebParam(name= “id”)int id)
-----------------------------------------------------------------------------------------------------------Step 5: Right Click on the webservice -> Add Operation -> choose the operation name and
return type.
Step 6: a. Right Click the project -> Deploy
c. In the web service folder, right click on the web service -> Test web service.
Step 7: Get into NetBeans IDE, go to File -> New Project -> Java -> Web Application
Give the name of the project as “clientticket”.
Step 8: Create a Home Page to receive sequence.
113. 44210205028
Step 9: Create component necessary to invoke the service from the client
d. Right click “clientticket” -> new -> WebServiceClient
e. Click Browse and select the required service.
Step 10: Build and Run the Web Application.
PROGRAM:
SERVER :
Web Service
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pack;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
import java.sql.*;
import javax.jws.Oneway;
/**
*
* @author student
*/
@WebService(serviceName = "ticketserv")
@Stateless()
public class ticketserv {
114. 44210205028
String name="";
String time="";
int id,amount,qty,lastid;
/**
* Web service operation
*/
@WebMethod(operationName = "getid")
public int getid(@WebParam(name = "id") int id) {
try
{ Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/mydb","student","student");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from APP.traintab where tid="+id);
while(rs.next())
{
id=rs.getInt("trainno");
}}
catch(Exception e)
{}
return id;
}
/**
* Web service operation
*/
@WebMethod(operationName = "getname")
public String getname(@WebParam(name = "id") int id) {
try
131. 44210205028
EX No: 5
DEVELOP A J2EE CLIENT TO ACCESS A .NET WEB SERVICE
DATE:
AIM:
To develop a J2EE client to access a .NET service.
ALGORITHM:
1. 1.Get into Visual studio new -> website->Asp.NET webservice choose language visual
C# . give project name.
2. Code the service(for getOrder)
Sample code
[WebMethod]
public int getOrderNumber(int seq)
{
Random r = new Random();
int ran = r.Next();
return ran;
}
3. Right click->project->build website
Click run for getting output
134. 44210205028
CREATION OF J2EE CLIENT TO ACCESS .NET WEB SERVICE
1.
Get into NETBean IDE, Go to file -> New project -> java web application. Give name as
orderapp.
2.
Create homepage to receive sequence and call the servlet whch will in turn call the order
webservice to generate order number.
3.
Create the component necessary and invoke the service from the client by right clik on
orderapp ->new -> webservice client.
4.
Create a servlet to make a call to the order webservice by right click on orderapp project
-> new ->servlet.
Create a servlet to make a call to the order web service. Name it orderservlet.
@WebServlet(name = "OrderServlet", urlPatterns = {"/ord"})
public class OrderServlet extends HttpServlet {
@WebServiceRef(wsdlLocation = "WEBINF/wsdl/localhost_1444/WebSite2/Service.asmx.wsdl")
private Service service;
135. 44210205028
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
org.tempuri.ServiceSoap port=service.getServiceSoap();
int ornum=port.getOrderNumber(Integer.parseInt(request.getParameter("seq")));
out.println("<html><body><h1>Generate order
number"+ornum+"</h1></body></html>");
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the +
sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
136. 44210205028
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
private int getOrderNumber(int seq) {
org.tempuri.ServiceSoap port = service.getServiceSoap();
return port.getOrderNumber(seq);
}
}
5.
Drag and drop the webservice reference created frm step 3 in the servlet.
Run the project
138. 44210205028
EX No: 6
DEVELOP A .NET CLIENT TO ACCESS A J2EE WEB SERVICE
DATE:
AIM:
To develop a .NET client to access a J2EE web service.
ALGORITHM:
1.
Get into the Netbean IDE, Go to File-> new Project -> Java web Application. Give the
name of the project as OrderserviceApp->next. Click finish to end.
2.
Right click OrderServiceApp project-> new-> webservice-> Give name as
OrderWebserive, package name as samp and click finish.
3.
Change the default web service with the code to generate ordernumber based on the
sequence given as parameter.
@WebMethod(operationName = "getOrderNumber")
public int getOrderNumber(@WebParam(name = "name") int seq) {
int ordernumber=(int)((Math.random()+seq)*10000000);
return ordernumber;
4.
Right click orderserviceapp project-> build and then deploy
5.
Right click OrderWebService->test web service.
139. 44210205028
CREATION OD .NET CLIENT TO ACCESS J2EE WEB SERVICE
1.
Get in visual studio new->website->ASP.NET website and choose language visual C# .
give project name.
2.
Right click->project->add web reference->give url of service press go.
Web reference is created.
3.
Go to default.aspx-> design view include a textbox and button to receive sequence and
invoke service.
On button click write the following code.
protected void Button1_Click(object sender, EventArgs e)
{
ord.OrderWebService s = new ord.OrderWebService();
Response.Write(s.getOrderNumber(Convert.ToInt32(TextBox1.Text)));
}
Build solution-> publish website.
4.
141. 44210205028
EX No: 7(a) DEVELOP A SERVICE ORCHESTRATION ENGINE USING WS BPEL
AND IMPLEMENT SERVICE COMPOSITION FOR CALCULATOR
DATE:
AIM:
To develop a service orchestration engine using ws bpel and implement service
composition for calculator.
CREATING A SERVICE
1.
2.
3.
4.
5.
Create a web service in Netbeans 6.5 called calcservice.
Open NetBeans6.5 , Select file-> Newproject-> javaEE-> EJB module. Click next.
Right click on the project window and select New-> Webservice
Name the service as calcservice. Pecify package as “pack”. Click on finish.
Type the following code.
CODE:
package pack;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ejb.Stateless;
public class calservice {
@WebMethod(operationName = "add")
public int add(@WebParam(name = "a")
int a, @WebParam(name = "b")
int b) {
//TODO write your implementation code here:
return a+b;
143. 44210205028
CREATING A BPEL PROJECT
1. Click on File new project and then click on SOA,then BPEL Name it as calcbpel.
144. 44210205028
2. Right click on the project, select new BPEL process and name it calcprocess Click
finish.
145. 44210205028
3. Drag the item under web service in calcservice and drag to the partner link.
4. Fill the Name as PartnerlinkWS and leave the other values and click ok.
146. 44210205028
STEPS TO DO
Creating another partner link :
1. Drag and drop the WSDL file again to the left hand side and name the partnerlink as
partnerlinkbpel.
2.
3.
4.
5.
6.
Click the Use a Newly Created Partner Link Type.
Check process will implement MyRole.
Fill the partner Link Type Name as calcServiceLinkTypeBPEL.
Fill the Role Name as calcServiceRoleBPEL.
Click on OK.
150. 44210205028
Choose the partner Link as PartnerLinkBPEL and Operation as add.
Click on create button besides Input Variable Label.
The Name Is usually Addin.Leave it as such and click ok.
158. 44210205028
Creating a composite application :
Click on New Project SOA CompositeApplication and name it calccompositeapp.
159. 44210205028
Enter the name and location of the composite application.
Now right click on the project add a JBI Module.
160. 44210205028
Drag the BPEL process from the calcBPEL project and drop in the JBI window.
Build the project.
161. 44210205028
Drag and drop soap entity from the palette and make the connections as below.
Select and delete the existing connections.
Establish the new connections as follows.
162. 44210205028
Then run the testcase after passing the value to the input file :
Create a new test case and give a name for it. Click next.
The related Wsdl documents will be displayed.
165. 44210205028
The Ouput is generated as below:
Now Build the BPEL project.
Run the project.
The following Xml document will be generated.
Change the argument values.
166. 44210205028
The sum for the given values will be displayed.
RESULT:
Thus a service orchestration engine using WSBPEL and implement service composition
for calculator is developed.
167. 44210205028
EX No: 7(b) DEVELOP A SERVICE ORCHESTRATION ENGINE(WORK FLOW)
USING WS-BPEL AND IMPLEMENT SERVICE COMPOSITION FOR
TRAVELS(AIRLINE)
DATE:
AIM:
Develop a Service Orchestration engine(work flow) using WS-BPEL and implement
service composition. To createa business process for planning business travels that will invoke
several services. This process will invoke several airline companies to check the airfare price and
buy at the lowest price.
PROCEDURE:
1) Create a sample web application :
File->new project-> in the catogories choose java web and in the projects tab select web
application->click next-> give a name for that new web application in the project name
(TestService1)-> accept the defaults and click finish.. In the projects tab our TestService1 has
been created.
168. 44210205028
2)Creation of Web Service:
Our web service reduces the amount by 5% and returns the value:
Right click our TestService1from that select new webservice. Give appropriate name to that web
service.
Web service name:TestWebservice
Package name: com.service
Make sure that create web service from scratch is selected.
Click finish.
3) Viewing for Our Web Service
Our new TestService.java web service opens up
Select the design tab->Click add operation
169. 44210205028
4) Creation of Operation for Our Web Service
Our web service takes in amount reduces 5% tax in that and returns the amount.
Input parameters:java.lang.Long
Output parameters:java.lang.Long
Operation name:TaxReduction
Click the add operation->a new add operation box pops up->in tha
name field:TaxService(operation name)
return type: click the browse button->type long-> select java.lang.Long from the option
parameters tab:InputAmount(NameFeild),long(Typefeild)
click ok
our TaxReduction operation shows up.->click the source view to write code
170. 44210205028
4) Paste the Code in our Operation
double amt=InputAmount-(InputAmount*0.05);
Long res=(new Double(amt)).longValue();
return res;
5) Click on the project tab there we can see our TestService web service in the web service
folder.
First right click the project and run the web application we created.
RightClick->TestWebservice to test our web service
172. 44210205028
7) We get the output as 142500
Similarly create another web service CheckRange web service this checks the input amount and
responds the type of travel based on the amount.
Here is the code for that service.
String res;
if(parameter<=5000){
res="eligible for bus travell";
}else if(parameter>5000&¶meter<=10000){
res="eligible for train travell";
}else{
res="eligible for flight travell";
}
return res;
173. 44210205028
7) BPEL CREATION
File->new->new project->select soa in catogories andBPEL module in project
Give a name for BPEL and accept the defaults.
Now a project is created and we have to create a BPEL right click on the project we created new>BPEL Process
Now give a name to our BPEL process and click finish. A sample BPEL file is created.
174. 44210205028
8) Now we need to create a client side interface to our BPEL process this is done by creating
WSDL file specifying the input to BPEL process and output from BPEL process
Right click project->new->new WSDL
Specify the name of the WSDL in the file name->click next
specify the inpu and output parameters in the WSDL ->cick next
for our scenario long is the input and string is the output from our BPEL process
->click next-> finish
Now a new WSDL client has been created for Sample BPEL process.
Drag the WSDL created in our BPEL Design window
9) Now drag the receive from the palette box into the BPEL diagram
176. 44210205028
11) Double click the receive and a new window opens click the create near the input variable a
new variable input variable opens accept the defaults and click ok.
12) Now drag the reply and connect a wire from reply to clientWSDL as same as receive
13) When you double click the reply you will get a window click the create button make sure
normal response is selected. Create new output variable opens. Click ok.
177. 44210205028
14) Now we have to create a partner link for web service invocation in our project.
Go to the project tab and go to the web service we created. Right click the TestService
webservice and select generate and copy WSDL. Select our BPEL project src folder and click
ok.WSDL is copied into our BPEL project drag the WSDL into our BPEL editor.
15) We need to invoke our web service method into our BPEL process. So we need to drag a
invoke method into BPEL between receive and reply now double click the invoke a new window
opens. Select the partner link just created(partnerlink 1) it drops down the operation in that select
the operation. click create for creating input variable.similarly for output variable.click ok
178. 44210205028
Similarly do the same for the next web Check rangeweb service we created.thus our BPEL
should contain two service invocation.
179. 44210205028
Our BPEL process should first get the long amount from client and pass it to TaxReduction web
service fro tax reduction and that output should be sent to checkrange service for checking range.
The output from that checkrange service will be the output from out entire BPEL process
16) Now we have to assign the client input to TaxReductionservice.first drag a assign from
palette and place it between receive and first invoke(TaxReduction). Double click assign . then
mapper tab opens up. We have to assign the clientWSDLoperationinput to taxreductioninput.
Click the clientWSDLoperationinput shows a part field.similarly click the Taxreduction
operation in parameters field opensclick that once again inputamount opens.Just drag a wire
frompart to inputamount.now we have assigned the BPEL input to taxreduction input.
17) Click on the design tab.now from taxreduction service to checkrange service.once again drap
the assign and place between the taxreductioninvoke and checkrangeinvoke.
181. 44210205028
Overall BPEL process design will look like this.
Now we have to specify the sopa address for the WSDLwe have imported. Select the imported
WSDL files in BPEL you can see services in the navigator window