Pratham Shindes Ws 49

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

INDEX

SR.NO Practical Name Date Signature


1 Write program to implement to create a 22/06/22
simple web service that converts that
Temperature from Fahrenheit to Celsius
and vice versa.
2 Write a program to implement the
operation can receive request and will
return a response in two ways.
A) One-way operation, 25/06/22
B) Request-Response. 27/06/22
3 Develop client which consumes web 11/07/22
services developed in different platforms.
4 Write a JAX-WS web service to perform 18/07/22
the following operations. Define a Servlet
/ JSP that consumes the web service.
5 Define a web service method that 01/08/22
returns the contents of a database in a
JSON string. The contents should be
displayed in a tabular format.
6 Define a RESTful web service that accepts 29/08/22
the details to be stored in a database and
performs CRUD operation.
7 Implement a typical service and a typical 07/09/22
client using WCF.
8 Use WCF to create a basic ASP.NET 14/09/22
Asynchronous JavaScript and XML (AJAX)
service.
9 Demonstrates using the binding attribute 14/09/22
of an endpoint element in WCF.
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 1: - Write program to implement to create a simple web


service that converts that Temperature from Fahrenheit to Celsius
and vice versa. Date: -22/06/22
Code: -
NetBeans code:
package com.mycompany.wspracticals;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService (serviceName = "Practical1Temp")


public class Practical1Temp {
@WebMethod (operationName = "CtoF")
public double CtoF (@WebParam (name = "C") double C) {
double f = C*1.8+32;
return f;
}

@WebMethod (operationName = "FtoC")


public double FtoC (@WebParam (name = "F") double F) {
double C = (F-32)/1.8;
return C;

1 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

FtoC

2 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

CtoF

3 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 2: - Write a program to implement the operation can


receive request and will return a response in two ways. A) One-way
operation, B) Request-Response.
Code: -
VISUAL STUDIO 2022 Code:
A) One-way operation Date: -25/06/22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Practical2
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.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 WebService1 : System.Web.Services.WebService
{

[WebMethod]
public int Addition (int x, int y)
{
return x + y;
}

[WebMethod]
public int Subtraction (int x, int y)
{

4 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

return x - y;
}

[WebMethod]
public int Multiplication (int x, int y)
{
return x * y;
}

[WebMethod]
public int Division (int x, int y)
{
return x / y;
}
}
}

O/P: -

5 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

6 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

7 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

8 Signature:
Sathish Pradhan Dnynasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

B) Request-Response Date: - 27/06/22


WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="Practical2B.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="1">
<tr>
<td>Enter number 1:</td>
<td><asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Enter number 2:</td>
<td><asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Display Result:</td>
<td><asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Button ID="Button1" runat="server" Text="Add(+)"
onclick="Button1_Click"/></td>
<td><asp:Button ID="Button2" runat="server" Text="Mul(*)"
onclick="Button2_Click"/></td>
</tr>
<tr>

9 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

<td><asp:Button ID="Button3" runat="server" Text="Sub(-)"


onclick="Button3_Click"/></td>
<td><asp:Button ID="Button4" runat="server" Text="Div(/)"
onclick="Button4_Click" /> </td>
</tr>
</table>
</div>
</form>
</body>
</html>

WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Practical2B
{
public partial class WebForm1 : System.Web.UI.Page
{
int a, b, c;
WebService1 obj = new WebService1();
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
a = Convert.ToInt16(TextBox1.Text);
b = Convert.ToInt16(TextBox2.Text);
c = obj.Add(a, b);
TextBox3.Text = c.ToString();
}

10 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

protected void Button2_Click(object sender, EventArgs e)


{
a = Convert.ToInt16(TextBox1.Text);
b = Convert.ToInt16(TextBox2.Text);
c = obj.Mul(a, b);
TextBox3.Text = c.ToString();
}

protected void Button3_Click(object sender, EventArgs e)


{
a = Convert.ToInt16(TextBox1.Text);
b = Convert.ToInt16(TextBox2.Text);
c = obj.sub(a, b);
TextBox3.Text = c.ToString();
}

protected void Button4_Click(object sender, EventArgs e)


{
a = Convert.ToInt16(TextBox1.Text);
b = Convert.ToInt16(TextBox2.Text);
c = obj.div(a, b);

TextBox3.Text = c.ToString();
}
}
}

WebService1.asmx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Practical2B
{
/// <summary>
/// Summary description for WebService1

11 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.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 WebService1 : System.Web.Services.WebService
{

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

internal int Add(int a, int b)


{
return a + b;
}

internal int Mul(int a, int b)


{
return (a * b);
}

internal int sub(int a, int b)


{
return a - b;
}

internal int div(int a, int b)


{
return a/ b;
}
}
}

12 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

13 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Addition:

Subtraction:

14 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Multiplication:

Division:

15 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 3: - Develop client which consumes web services developed


in different platforms. Date: -11/07/22
Code: -
NetBeans code:
package com.mycompany.wspracticals;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "Practical4")
public class Practical4 {
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
}

16 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

17 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

VISUAL STUDIO 2022 Code:


WebService1.asmx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebApplication1.ServiceReference1;
using System.Web.Services;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.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 WebService1 : System.Web.Services.WebService
{

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

}
}
}

18 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
WebService Communication With Different Paltform
<table>
<tr>
<td>Enter Your Name:</td>
<td> <asp:TextBox ID="TextBox1"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Clear"
OnClick="Button1_Click" /></td>
<td>
<asp:Button ID="Button2" runat="server" Text="Submit"
OnClick="Button2_Click" /></td>
</tr>
<tr>
<td><asp:Label ID="Label1" runat="server"
Text="Welcome:"></asp:Label></td>
<td><asp:Label ID="Label2" runat="server"
Text="Label"></asp:Label></td>
</tr>
</table>
</div>
</form>
</body>
</html>

19 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button2_Click(object sender, EventArgs e)


{
String str1 = TextBox1.Text;
ServiceReference1.Practical4Client cc = new
ServiceReference1.Practical4Client();
Label2.Text = cc.hello(str1);
}

protected void Button1_Click(object sender, EventArgs e)


{
TextBox1.Text = "";
}
}
}

20 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

21 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 4: - Write a JAX-WS web service to perform the following


operations. Define a Servlet / JSP that consumes the web service.
Date: -18/07/22
Code: -
NetBeans code:
UserWebService
package server;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "StudentWebService")
public class StudentWebService {
@WebMethod(operationName = "StudentDetails")
public String StudentDetails(@WebParam(name = "Roll No") String RollNo,
@WebParam(name = "Student Name") String StudentName,
@WebParam(name = "Student Class") String StudentClass) {
return "Welcome: Roll No: " +RollNo+ "\t Student Name: "
+StudentName+ "\t Student Class: " +StudentClass;
}
}

22 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

ProgramServlet
import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import server.UserWebService;

public class ProgramServlet extends HttpServlet {


protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String RollNo,StudentName,StudentClass;
RollNo = request.getParameter("SRN");
StudentName = request.getParameter("SName");
StudentClass = request.getParameter("SClass");
StudentWebService obj = new StudentWebService();
out.println("The User Detalis is: " +
obj.StudentDetails(RollNo,StudentName,StudentClass));
}
}

23 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Program1.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>Web Service User Form Details</h1>
<hr size = "4" color = "orange">
<form action="ProgramServlet">
Roll No: <input type="text" name="SRN" value="" /><br>
Student Name: <input type="text" name="SName" value="" /><br>
Student Class: <input type="text" name="SClass" value="" /><br><br>
<input type="submit" value="Submit" />
</form> <hr size = "4" color = "orange">
</body>
</html>

24 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

25 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 5: - Define a web service method that returns the contents


of a database in a JSON string. The contents should be displayed in a
tabular format. Date: - 01/08/22
Code: -
SQL Server Management Studio:
----Create a table----
Create table tblEmployees
(
Id int primary key identity,
Name nvarchar(50),
Gender nvarchar(10),
Salary int
)
Go

----Record Insertinto table----


Insert into tblEmployees values ('Tanay', 'Male', 55000)
Insert into tblEmployees values ('Sakshi', 'Female', 68000)
Insert into tblEmployees values ('Vinay', 'Male', 57000)
Insert into tblEmployees values ('Pooja', 'Female', 53000)
Insert into tblEmployees values ('Amey', 'Male', 60000)

----Create one Stored Procedure named “AngularDB”----


Create Procedure AngularDB
As
Begin
select * from tblEmployees
End

----Execute this Stored Procedure to check the records----


execute AngularDB

26 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

VISUAL STUDIO 2022 Code:


Web.Config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please
visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="MyDB" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=Data1;Integrated
Security=True"/>
</connectionStrings>
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>

27 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

</webServices>
<compilation debug="true" targetFramework="4.7.1" />
<httpRuntime targetFramework="4.7.1" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodePro
vider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform,
Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default
/nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvide
r, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008
/define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
</configuration>

Employees.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Practical6

{
public class Employees
{
public int id { get; set; }
public string name { get; set; }
public string gender { get; set; }
public int salary { get; set; }
}}

28 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

EmployeesService.asmx
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;

namespace Practical6
{
/// <summary>
/// Summary description for EmployeesService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.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 EmployeesService : System.Web.Services.WebService

{
[WebMethod]
public void GetAllEmployees()
{
List<Employees> listEmployees = new List<Employees>();
string cs =
ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "AngularDB";
con.Open();

29 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

SqlDataReader rdr = cmd.ExecuteReader();


while (rdr.Read())
{
Employees employees = new Employees();
employees.id = Convert.ToInt32(rdr["Id"]);
employees.name = rdr["Name"].ToString();
employees.gender = rdr["Gender"].ToString();
employees.salary = Convert.ToInt32(rdr["Salary"]);
listEmployees.Add(employees);
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(listEmployees));
}
}
}

30 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

31 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 6: - Define a RESTful web service that accepts the details to


be stored in a database and performs CRUD operation.
Date: - 29/08/22
Code: -
NetBeans code:
HelloServlet:
package helloworld;
import com.mycompany.helloworldapplication.HelloWorld;
import java.io.IOException;
import java.sql.*;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {


@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<form action = HelloServlet>");

32 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

out.println("Enter UserName<input type = text name = uname>");


out.println("<input type = submit value = Submit>");
out.println("</form>");
try{
HelloWorld obj = new HelloWorld();
String uname = request.getParameter("uname");
obj.putHtml(uname);
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/db1","Tanay","Ta
nay@241002");
PreparedStatement ps = con.prepareStatement("insert into
tbluser(username)values(?)");
ps.setString(1, obj.getHtml());
ps.executeUpdate();
out.println("Data Successfully Insert!!!!");
ResultSet rs = ps.executeQuery("select * from tbluser");
out.println("<table border=1 width=50%>");
out.println("<tr><th>UserID</th><th>Username</th></tr>");
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getInt(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td>");
out.println("</tr>");
}

33 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

out.println("</table>");
}catch(Exception ex){out.println(ex.getMessage());}
}
}

HelloWorld:
package com.mycompany.helloworldapplication;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;

@Path("generic")
public class HelloWorld {

@Context
private UriInfo context;
private String username;

34 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

@GET
@Produces(MediaType.TEXT_HTML)
public String getHtml() {
return username;
}
@PUT
@Consumes(MediaType.TEXT_HTML)
public void putHtml(String uname) {
this.username = uname;
}
}

O/P: -

35 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 7: - Implement a typical service and a typical client using


WCF. Date: -07/09/22
Code: -
VISUAL STUDIO 2022 Code:
IService1.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace Practical8
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to
change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
int sum(int a, int b);

[OperationContract]
int Subtract(int a, int b);

[OperationContract]
int Multiply(int a, int b);

[OperationContract]
int Divide(int a, int b);
}
}

36 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Service1.svc.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace Practical8
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to
change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please
select Service1.svc or Service1.svc.cs at the Solution Explorer and start
debugging.
public class Service1 : IService1
{
public void DoWork()
{
}
public int sum(int a, int b)
{
return a + b;
}

public int Subtract(int a, int b)


{
if (a > b)
{
return a - b;
}
else
{
return 0;
}
}
public int Multiply(int a, int b)

37 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

{
return a * b;
}

public int Divide(int a, int b)


{
if (b != 0)
{
return (a / b);
}
else
{
return 1;
}
}
}
}

O/P: -

38 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Subtraction:

Addition:

39 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Multiplication:

Division:

40 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 8: - Use WCF to create a basic ASP.NET Asynchronous


JavaScript and XML (AJAX) service. Date: -14/09/22
Code: -
VISUAL STUDIO 2022 Code:
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication4.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Service.svc" />
</Scripts>
</asp:ScriptManager>
</div>
<div class="auto-style1">
Enter UserName <asp:TextBox ID="TextBox1" runat="server"
Height="24px"></asp:TextBox> <br />
<br />
<asp:Button ID="Button1" runat="server" Height="24px"
OnClick="Button1_Click" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Welcome"
Height="24px"></asp:Label>
:&nbsp;&nbsp;

41 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

<asp:Label ID="Label2" runat="server" Text="Label"


Height="24px"></asp:Label>
</div>
</form>
</body>
</html>

Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication4
{
public partial class Default : System.Web.UI.Page
{
Service1 ss = new Service1();
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string a;
a = ss.MCNUSER(TextBox1.Text);
Label2.Text = a.ToString();
}
}
}

42 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Service1.svc:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace WebApplication4
{
[ServiceContract(Namespace = "MCNSOLUTION")]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
[OperationContract]
public void DoWork()
{
return;
}
[OperationContract]
public string MCNUSER(string UNAME)
{
return "HELLO MCN " + UNAME;
}
}
}

43 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

O/P: -

44 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

Practical 9: - Demonstrates using the binding attribute of an


endpoint element in WCF. Date: -14/09/22
Code: -
VISUAL STUDIO 2022 Code:
App.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata/>
<serviceDebug/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress =
"net.tcp://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service
1/" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="tcp" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>

45 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

<endpoint address="mex" binding="mexTcpBinding"


bindingConfiguration="" name="mextcp" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
</configuration>

O/P: -
GetData:

46 Signature:
Sathish Pradhan Dnyanasadhana College, Thane [A.Y. 2022-2023]
Pratham A. Shinde WS Practical Journal Roll Number: -49

GetDataUsingDataContract:

Client.dll.config:

47 Signature:

You might also like