WEBSERVICE
USING APACHE AXIS TUTORIAL-1
Using Java
XML-WEBSERVICE from ASP.net.
( published in
DeveloperIQ January-2004)( www.developeriq.com)
R.S.RAMASWAMY ([email protected])
Sri.Manoj Kothale, has written a fine piece in
DeveloperIQ(Nov'03) on exposing an EJB
as an XML-WebService, using Axis and JBOss. In this experiment, we attempt exposing a
javabean (jws) from Tomcat/Axis and consuming that service
in an ASP.net program.This is much simpler.
Inter-operability is one of the two aims of Xml-webservice
paradigm,while the other aim is tackling the firewall problem. (Since ASP.net
runs only in Win2000, switch over to Win2000. before beginning this
experiment).The emphasis is on the procedure, in laboratory experiment
fashion).
Kindly , ensure
that correct versions of software , are used, as mentioned.It is presumed that
DotNet SDK has already been installed and tested,for running asp.net programs.
1) axis1.1 was installed in
2) tomcat4.1 from march-2003 issue of Dev IQ.
was installed as c:\tomcat41
3) We
will find a folder named 'axis'
in c:\axiss11\webapps.
Copy this ('axis')
folder to c:\tomcat41\webapps folder.
4) We must copy activation.jar to:
c:\tomcat41\webapps\axis\web-inf\lib
folder. (This file is available in jboss3.2\server\all\lib
folder
and jboss3.2 was given in NovemberCD.)
5) We
set JAVA_HOME for tomcat as follows:
c:\tomcat41\bin>set JAVA_HOME=D:\jdk141
(because, we have installed jdk1.4.1 in
D-drive).
6) We should uncomment the 'admin servlet'
part in
the web.xml file in c:\tomcat41\webapps\axis\web-inf folder.
7) We start tomcat server:
c:\tomcat41\bin>startup
8) This starts tomcat4.1 and we wait till,
it is fully started.
In this folder, we create a simple
javabean greeter.java as given below.
// c:\axisdemo\greeter.java
public class greeter
{
public String greetme(String s)
{
return "How are
you???????.."+s;
}
}
10) we copy greeter.java as greeter.jws
into c:\tomcat41\webapps\axis
folder.
(we did this while tomcat41 was
running!).No problem!
11) We start the browser and type the URL as:
'http://localhost:8080/axis/greeter.jws'
and we get a link to the wsdl file for the above
service. When we click this link, we get a
wsdl file .
(wsdl -> webservice description
language).
12) We save this wsdl file in d:\inetpub\wwwroot
folder as greeter.wsdl
13) Our aim is to create a C# file from this wsdl file.
The following command does that.
d:\inetpub\wwwroot>wsdl greeter.wsdl
This command created
greeterService.cs
file!
( carefully
note that the name has been appended with 'Service')
The next step is to compile this
source file into a dll.
14)..wwwroot>csc /t:library
/r:System.dll,System.Web.Services.dll,System.Xml.dll
greeterService.cs
(type this in continuous line).
( t -> target & r -> reference)
This command created greeterService.dll
15) Now copy this dll file to d:\inetpub\wwwroot\bin
folder.
( If there is no such 'bin' folder create it.).
Now create greeterService.aspx as given below.
( in d:\inetpub\wwwroot
folder)
<%@ page
language="c#" %>
<script
runat=server>
public void
job1(Object o, EventArgs e)
{
String a = text1.Text;
greeterService greeter = new
greeterService();
String s = greeter.greetme(a);
Response.Write(s);
}
</script>
<html>
<body>
<form runat=server>
<asp:Textbox id=?text1?
runat=server />
<asp:Button onclick=job1 text="Click"
runat=server />
</form>
</body>
</html>
( Normally, IIS-5 will be running . If not,
start it.)
'http://localhost/greeterService.aspx'
Remember that the tomcat server is running
and supplying the 'greeter.jws'.
After some delay ( due to compiling time),
we get a form.Type your name in the textbox ( say, ?sam?
)& click the button to invoke the service.
Ref: AXIS..by RominIrani & JeelaniBasha (wrox press).
Visit http://in.geocities.com/rsramsam 6