WebService




file->new website->ASP.NET web service  language: C#

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

[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 Service : System.Web.Services.WebService
{
    public Service () {

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

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    [WebMethod]
    public double f_c(double t)
    {
        return(((t-32)*5)/9);
    }
    [WebMethod]
    public double c_f(double t)
    {
        return (((t*9)/5)+32);
    }


}


save and run (press F5)




file->new website->ASP.NET web service  language: C#

design 




add web reference:



Website
using System;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Focus();
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
       
       
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        double z;
        temp.Service obj = new temp.Service();
        if (TextBox1.Text=="")
        {
            Type cstype = this.GetType();
            ClientScriptManager cs = Page.ClientScript;
            if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
            {
                String cstext = "alert('Please Enter Value');";
                cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);

            }
        }
        else
        {
            if (DropDownList1.Text == "Fahrenheit to Celsius")
            {
                z = obj.f_c(double.Parse(TextBox1.Text));

                Label2.Text = z.ToString() + "  C";
            }
            else if (DropDownList1.Text == "Celsius to Fahrenheit")
            {
                z = obj.c_f(double.Parse(TextBox1.Text));
                Label2.Text = z.ToString() + "  F";
            }
            else
            {
                Type cstype = this.GetType();
                ClientScriptManager cs = Page.ClientScript;
                if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                {
                    String cstext = "alert('Please Select Conversion');";
                    cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);

                }
            }
        }

    }
}

save and run (press F5)
output




COM COMPONENT TO PERFORM LOGOCAL OPERATIONS USING DOTNET



file->new project->Visual C#->ClassLibrary


DLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
    public class Class1
    {
        public
          int  andop(int a,int b)
        {
            return(a*b);
        }


        public
            int orop(int a, int b)
        {
            if (a == 0 && b == 0)
                return (0);
            else
                return (1);
        }


        public
            int notop(int a)
        {
            if (a == 0)
                return (1);
            else
                return (0);
        }


        public
            int nandop(int a, int b)
        {
            if (a == 1 && b == 1)
                return (0);
            else
                return(1);
        }
        public
            int norop(int a, int b)
        {
            if (a == 0 && b == 0)
                return (1);
            else
                return (0);
        }


        public
            int xorop(int a, int b)
        {
            if (a == b)
                return (0);
            else
                return (1);
        }

        public
            int xnorop(int a, int b)
        {
            if (a == b)
                return (1);
            else
                return (0);
        }

    }
}

 build a class library (press F5)

--------------------------------------------------------------------------
 file->new project->Vb->WindowsApplication

add a dll file
project->add reference->browse to select dll and clik ok

CODING
Imports ClassLibrary1

Public Class Form1
    Dim obj As Class1 = New Class1
    Dim a, b As Integer


    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        a = Val(ComboBox1.Text)
        b = Val(ComboBox2.Text)

        If ComboBox3.Text = "AND" Then
            TextBox1.Text = obj.andop(a, b)
            ComboBox2.Visible = True

        ElseIf ComboBox3.Text = "OR" Then
            TextBox1.Text = obj.orop(a, b)
            ComboBox2.Visible = True

        ElseIf ComboBox3.Text = "NOT" Then
            ComboBox2.Visible = False
            TextBox1.Text = obj.notop(a)

        ElseIf ComboBox3.Text = "NAND" Then
            TextBox1.Text = obj.nandop(a, b)
            ComboBox2.Visible = True

        ElseIf ComboBox3.Text = "NOR" Then
            TextBox1.Text = obj.norop(a, b)
            ComboBox2.Visible = True
      
        End If



    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        ComboBox2.Visible = True

    End Sub
End Class





OUTPUT



OPEN NOTEPAD USING CORBA



Idl file   notepad.idl
module notepad
{
interface note
{
string display();
};
};
Implementation file  noteimpl.java
import notepad.*;
import org.omg.CORBA.*;
import java.io.*;
public class noteimpl extends notePOA
{

private ORB orb;

public noteimpl(ORB orb)
{
this.orb = orb;
}

public String display()
{
return("C:\\WINDOWS\\system32\\notepad");
}
}
Server file   noteserv.java
import notepad.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
public class noteserv
{
public static void main(String args[])
{
try
{
ORB orb = ORB.init(args,null);
noteimpl impl = new noteimpl(orb);
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(impl);
note wref = noteHelper.narrow(ref);
org.omg.CORBA.Object objref = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objref);
NameComponent nc = new NameComponent("note","");
NameComponent path[] = {nc};
ncRef.rebind(path,wref);
System.out.println("Server ready & waiting.....");
orb.run();
}
catch(Exception e)
{
System.err.println("ERROR"+e);
}
System.out.println("Server Exiting............");
}
}
Client file   notecli.java
import notepad.*;
import java.io.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class notecli
{
public static void main(String args[])throws IOException
{
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
NameComponent nc = new NameComponent("note","");
NameComponent path[] = {nc};
note impl = noteHelper.narrow(ncRef.resolve(path));
Runtime r=Runtime.getRuntime();
r.exec(impl.display());
}
catch(Exception e)
{
System.out.println("ERROR:"+e);
}
}
}

Compilation

D:\kar\New Folder\serv>set path=C:\Program Files\Java\jdk1.6.0\bin

D:\kar\New Folder\serv>idlj -fall note.idl

D:\kar\New Folder\serv>cd notepad

D:\kar\New Folder\serv\notepad>path.bat

D:\kar\New Folder\serv\notepad>set path=C:\Program Files\Java\jdk1.6.0\bin

D:\kar\New Folder\serv\notepad>javac *.java
Note: notePOA.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

D:\kar\New Folder\serv\notepad>cd..

D:\kar\New Folder\serv>javac *.java

D:\kar\New Folder\serv>tnameserv
Initial Naming Context:
IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578744578743a312e30000000000001000000000000009a000102000000000e3139322e3136
382e312e32303200038400000045afabcb0000000020000f42400000000100000000000000020000
0008526f6f74504f41000000000d544e616d65536572766963650000000000000008000000010000
00011400000000000002000000010000002000000000000100010000000205010001000100200001
0109000000010001010000000026000000020002
TransientNameServer: setting port for initial object references to: 900
Ready.
Open new window

D:\kar\New Folder\serv>set path=C:\Program Files\Java\jdk1.6.0\bin

D:\kar\New Folder\serv>java noteserv
Server ready & waiting.....
Open new window

D:\kar\New Folder\serv>java notecli

D:\kar\New Folder\serv>

Output





SEARCH A NUMBER IN AN ARRAY USING CORBA


Idl file   inter.idl
module searchapp
{
typedef long a[20];
interface inter
{
long search(in long a,in a a1 ,in long item);
};
};

Implementation file    searchimp.java
import searchapp.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
class searchimp extends interPOA
{
private ORB orb;
public searchimp()
{
}
public int search(int s,int r[],int n)
{
int i,f = 0;
for(i=0;i<n;i++)
{
if(r[i] == s)
{
f=1;
break;
}
}
if(f == 1)
{
i=i;
System.out.println("Element is found"+r[i]);
i=i+1;
System.out.println("The Position is"+i);
}
else
{
System.out.println("Element not found");
}
return(i);
}
public void setORB(ORB orb_val)
{
orb=orb_val;
}
}

Server file  searchserver.java

import searchapp.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
public class searchserver
{
public static void main(String args[])
{
try
{
ORB orb = ORB.init(args,null);
POA rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
searchimp noteref = new searchimp();
noteref.setORB(orb);
org.omg.CORBA.Object ref =rootpoa.servant_to_reference(noteref);
inter href=interHelper.narrow(ref);
org.omg.CORBA.Object obref=orb.resolve_initial_references("NameService");
NamingContext ncref = NamingContextHelper.narrow(obref);
NameComponent nc=new NameComponent("inter","");
NameComponent path[] = {nc};
ncref.rebind(path,href);
java.lang.Object sync=new java.lang.Object();
synchronized(sync)
{
sync.wait();
}
}
catch(Exception e)
{
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}

Client file  searchclient.java

import searchapp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import java.io.*;
public class searchclient
{
public static void main(String args[])
{
int r[],i;
r=new int[20];
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object obref = orb.resolve_initial_references("NameService");
NamingContext ncref = NamingContextHelper.narrow(obref);
NameComponent nc=new NameComponent("inter","");
NameComponent path[] = {nc};
inter href = interHelper.narrow(ncref.resolve(path));
java.io.DataInputStream dts=new java.io.DataInputStream(System.in);
System.out.println("Enter size of Array:");
int n= Integer.parseInt(dts.readLine());
System.out.println("Enter elements of array:");
for(i=0;i<n;i++)
{
r[i]=Integer.parseInt(dts.readLine());
}
System.out.println("Enter element you want to search:");
int a=Integer.parseInt(dts.readLine());
href.search(a,r,n);
}
catch (Exception e)
{
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
                   }
                }
            }








Compilation



D:\kar\New Folder\search>set path=C:\java\jdk1.6.0\bin;

D:\kar\New Folder\search>idlj -fall inter.idl


D:\kar\New Folder\search>cd searchapp


D:\kar\New Folder\search\searchapp>path.bat

D:\kar\New Folder\search\searchapp>set path=C:\java\jdk1.6.0\bin;

D:\kar\New Folder\search\searchapp>javac *.java
Note: interPOA.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

D:\kar\New Folder\search\searchapp>cd..

D:\kar\New Folder\search>javac *.java
Note: searchclient.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

D:\kar\New Folder\search>

D:\kar\New Folder\search>tnameserv
Initial Naming Context:
IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578744578743a312e30000000000001000000000000009a000102000000000e3139322e3136
382e312e32303200038400000045afabcb0000000020000f42400000000100000000000000020000
0008526f6f74504f41000000000d544e616d65536572766963650000000000000008000000010000
00011400000000000002000000010000002000000000000100010000000205010001000100200001
0109000000010001010000000026000000020002
TransientNameServer: setting port for initial object references to: 900
Ready.

open new window

D:\kar\New Folder\search>java searchserver

open new window

D:\kar\New Folder\search>java searchclient
Enter size of Array:
5
Enter elements of array:
11
22
33
44
55
Enter element you want to search:
44

output on server window


D:\kar\New Folder\search>java searchserver
Element is found44
The Position is4




Your IP Address is:

Browser: