Thursday, March 24, 2022

Creating and Using Web Services

What is Web Service? 

A Web Service is a reusable piece of code used to communicate among different Applications. Once a web service is created and hosted on the server in the internet it can be used by any application developed.

A file with .asmx extensions is an ASP.NET Web Service file that provides communication between two objects over the internet using the Simple Object Access Protocol (SOAP).

Creating and Using Web Services

Steps to create web service:

Step 1: Open .Net Visual Studio, create an Empty web site.

Step 2: Right click on App location in Solution Explorer and Select “Add New Item”, from add new item dialog box select and add “WebService” file with “.asmx” extension.
This file contains some program line as given below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

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

    public WebService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

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

From above line of code the part 

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
Containing the methods used as web services. You can add your own methods, like

[WebMethod]
    public int MyCalc(int x, int y)
    {
        return x * y;
    }
Accordingly go on adding methods as per the need of our web application.

Step 3: To test these newly added methods just execute the project, it will run in web browser, and the following output will be observed. After Executing it will display the names of web services.





To execute these services just click on the name of the web service. The output screen of “MyCalc” web service can be shown as

As MyCalc service requires two parameters, it will ask for two values.

Making the use of web service in the Web Application:

Step1: To make use of this Web Service add an Web Form (i.e. Default.aspx page) in the project.

Step 2: Right click in solution explorer, select “add web reference”, this will open Add Web Reference dialog box, from the dialog box, Click on “Select Web Services in this solution” as shown in the figure.



Step 3: From the dialog box above click on the Add Reference button. This will add “.disco” and “.wsdl” files in the application.
(Note: WSDL: WSDL stands for Web Service Description Language. It is written in XML and also specifies the location of the service and the methods used.
 
XML grammar describes details such as:-
1. Where we can find the Web Service (its URI)?
2. What are the methods and properties that service supports?
3. Data type support.
4. Supported protocols

The DISCO (is the abbreviated form of Discovery) file typically points to a WSDL(Web Service Description Language) source that in turn points to the actual Web Service.When one searches for the Web Services, it will go to the DISCO which gives actual information for the particular Web services. It has .disco file extension. It is an XML document which contains link to another resources.)

 
Step 4: Now add two textbox controls and a button control, and on the click event of button control add the following line of code in code behind model of the Default.aspx file.

        localhost.WebService wc = new localhost.WebService();
        int a = int.Parse(TextBox1.Text);
        int b = int.Parse(TextBox2.Text);
        int c = wc.MyCalc(a, b);
        Label1.Text = "Answer is " + c.ToString();


Monday, March 21, 2022

Interaction with Hardware through 'C'

 Interrupt & Interrupt Vector table

What is Interrupt?

The interrupt is a signal produced by hardware or software when a process or an event needs immediate attention. It alerts the processor of a system to stop / suspend the current working process and give attention to the process which generates an interrupt.

After the execution of the interrupt service routine, the processor resumes the execution of the suspended program / process.

There are two types of interrupts

i)      Software Interrupt

A software interrupt is caused either by an exceptional condition or a special instruction in the program, which causes an interrupt when it is executed by the processor.

ii)    Hardware Interrupt

A hardware interrupt is an electronic signal sent to the processor from an external device or an external peripheral. For example, when we press a key on the keyboard or move the mouse, they trigger hardware interrupts which cause the processor to read the keystroke or mouse position.

Interrupt Vector Table:

The interrupt vector table, often abbreviated to IVT, is a data structure that associates a list of interrupt handlers i.e. an array of pointers to functions. The IVT and the handlers are used to handle specific exceptions, such as faults, system service requests from the application, and interrupt requests from peripherals.

ROMBIOS Philosophy:

Calling a ROM-BIOS functions is not so simple, because, ROM-BIOS functions do not have names. These can be called by obtaining their addresses, and passing control to these addresses. The addresses of ROM-BIOS functions are stored in the Interrupt Vector Table (IVT).

At the specific moment when the ROM-BIOS function is called, the microprocessor is usually busy doing something; and the microprocessor is capable of performing only one task at a time.

All ROM-BIOS functions are invoked through 'interrupts'. Each interrupt instruction selects a particular address in the IVT and passes control to this address. This design makes it possible for any program to use a ROM-BIOS function without knowing its specific memory location.

There are numerous ROM-BIOS functions available. They have been divided into subject categories, each with its own controlling interrupt. For example, all functions related with VDU are grouped under interrupt number 16, all functions related with printer are grouped under interrupt number 23 and so on.

Invoking ROM-BIOS Function:

To call ROM-BIOS function we should perform the following steps:

i)       Make an Interrupt occur.

ii)     Find the interrupt number occurred

iii)  Obtain the address of Interrupt Service Routine form IVT

iv)   Place the values in CPU registers as required by ROMBIOS function

v)     Execute the ROMBIOS function

From the steps above, except for steps (i) and (iv) all other steps are performed by the microprocessor itself. So our task is just place the values needed by the ROM-BIOS routine and make a software interrupt to occur.

In language ‘C’ the software interrupt can be caused by using the standard library function int86( ), this function is also used to place values in CPU registers, as required by the ROM-BIOS function.

The ROM-BIOS functions have been written in such a manner that, some functions expect values to be placed in registers AX, BX, CX etc., whereas some functions expect a different value in high byte (AH) of AX register, and a different value in low byte (AL) of AX register, and so on.

int86( ) function

The int86() is a standard library function present in the <dos.h> header file, is used to make a software interrupt occur and thus invoke a ROM-BIOS function. Here int stands for interrupt and 86 refers to the 8086 family of microprocessors.

The function int86( ) requires three arguments:

-          An interrupt number corresponding to the ROM-BIOS function to invoked.

-          Two union variables. The first union variable represents the value being sent to the ROM-BIOS routine and the second variable represents the value which being returned from ROM-BIOS routines.

 

The general syntax for int86( ) function is:

            int86( interrupt_no, inputRegis, outputRegis);

Example:

            Int86(16, &inregs, &outregs);

Here 16 is the interrupt number, inregs represents the register value to be sent to ROM-BIOS function and outregs represents the register value returned by the ROM-BIOS function.

Interrupts to access ROMBIOS Services.

There are number of ROM-BIOS services available, these services are grouped together according to their similarities under one interrupt for example the interaction with VDU / Monitor are grouped together under interrupt number 16.

The following table gives description of some of the ROM-BIOS services under that interrupt number.



Friday, March 18, 2022

Bit wise Operators in C

 Bit Operations

 One's Compliment operator

    Ø  Bitwise one's compliment operator will invert the binary bits.

Ø  Bitwise compliment operator is an unary operator. It is denoted by ~.

Ø  It changes 1 to 0 and 0 to 1. i.e. If a bit is 1, it will change it to 0. and If the bit is 0, it will change it to 1.

 Let’s consider a number 5.

 Then ~5 will be,

5 = (00000101)2

~5 = (11111010)2. It will convert all 1 to 0 and 0 to 1.

 Program:

 #include <stdio.h>

#include <conio.h>

void main()

{

   int a = 9; 

   int c;          

   c = ~(a);     

   printf("The Ones Complement is %d", c);

   getch();

}

Right shift Operator: The right shift operator is represented by >>. It needs two operands. It shifts each bit in its left operand to the right.

The >> (right shift) in C takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift. In other words, right shifting an integer “a” with an integer “b” can be denoted as a>>b.

 For example: if the variable ch contains the bit pattern 11010111, then, ch >> 1 would give 01101011

 Program:

     #include <stdio.h>

#include <conio.h>

void main()

{

   int a = 5; 

   int c;          

   c = a>>1;     

   printf("After Right Shift result is %d", c);

   getch();

}

 Left shift Operator: The left shift operator is represented by <<. It needs two operands. It shifts each bit in its left operand to the left.

The << (left shift) in C takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift. In other words, left shifting an integer “a” with an integer “b” can be denoted as a<<b.

 For example: if the variable ch contains the bit pattern 11010111, then, ch << 1 would give 10101110



Program:

      #include <stdio.h>

#include <conio.h>

void main()

{

   int a = 5; 

   int c;          

   c = a<<1;     

   printf("After Left Shift result is %d", c);

   getch();

}

 

Bit wise operator- AND

This operator is represented as &. It is different than &&, the logical AND operator. The bit wise & operator operates on two operands. While operating upon these two operands they are compared on a bit-by-bit basis so both the operands must be of the same data type.

The rules for bit wise & operations are as follows:

 


For example:

A=5;

B=4;

C = A & B

It can be represented as

00000101            Original Bit Pattern

00000100             Mask with 4

----------------

00000000             Result

 

Program:

      #include <stdio.h>

#include <conio.h>

void main()

{

   int a = 5, b = 4; 

   int c;          

   c = a & b;     

   printf("After AND operation result is %d", c);

   getch();

}

Bit wise operator- OR

This operator is represented as |. It is different than ||, the logical OR operator. The bit wise | operator operates on two operands. While operating upon these two operands they are compared on a bit-by-bit basis so both the operands must be of the same data type.

 The rules for bit wise | operations are as follows:

 


For example:

A=5;

B=4;

C = A | B

It can be represented as

00000101            Original Bit Pattern

00000100             Mask with 4

----------------

00000101             Result

 Program:

      #include <stdio.h>

#include <conio.h>

void main()

{

   int a = 5, b = 4; 

   int c;          

   c = a | b;     

   printf("After OR operation result is %d", c);

   getch();

}

Bit wise operator- XOR

This operator is represented as ^. The bit wise ^ operator operates on two operands. While operating upon these two operands they are compared on a bit-by-bit basis so both the operands must be of the same data type.

 The rules for bit wise ^ operations are as follows:



 For example:

A=5;

B=4;

C = A ^ B

It can be represented as

00000101            Original Bit Pattern

00000100             Mask with 4

----------------

00000001             Result

 

Program:

      #include <stdio.h>

#include <conio.h>

void main()

{

   int a = 5, b = 4; 

   int c;          

   c = a ^ b;     

   printf("After XOR operation result is %d", c);

   getch();

}