Insert Title Here

Download Report

Transcript Insert Title Here

Creating Web Services
Presented by
Ashraf Memon
Overview
•
•
•
•
Writing service classes in Java
Generating service
Deploying services with Apache Axis
Generating client files and testing them
2
Writing service classes in Java
• Service classes are exactly similar to normal
Java classes:
– Nothing new to learn from development
perspective
– Any existing Java Class can be converted into
web service.
• Next slide explains fragments of simple
Java class which adds two numbers.
3
Writing service classes in Java
(contd)
• Class contains 1 function which performs
addition.
• Function signature is
public String sum(int num1, int num2)
• Function implementation is
int answer = num1+num2;
return "Sum of "+num1+" and "+num2+"
is "+answer;
• Complete class code follows on next slide.
4
Writing service classes in Java
(contd)
public class Math {
public String getSum(int num1, int num2){
int answer = num1+num2;
return "Sum of ” + num1 + " and "+ num2 +
" is ” + answer;
}
public static void main(String[] args) {
int num1=3;
int num2=4;
5
Writing service classes in Java
(contd)
Math sampleProgram = new Math();
String reply = sampleProgram.getSum(3,4);
System.out.println(reply);
}
}
6
Generating Service
• Download MathService directory from
ftp://dotnet.sdsc.edu/CSIG-WS/
• Save directory to C:\training\user\code
• Compile Math.java file by typing following
at command prompt
javac Math.java
• Run program by typing following at
command prompt
java Math
7
Generating Service (contd)
• Output should be
Sum of 3 and 4 is 7
8
Deploying services with Apache
Axis
• Copy generated class file to
C:\training\tools\tomcat\webapps\axis\WEB
-INF\classes\
• Open deployMath.wsdd in Textpad
(Explanation by instructor)
• Close file.
9
Deploying services with Apache
Axis(contd)
• Set classpath by typing classpath at
command prompt
• Execute deployment descriptor by typing
deploy deployMath.wsdd at command
prompt.
• This deploys webservice on Axis SOAP
Server.
10
Generating client files and
testing them(contd)
• Compile MathServiceClient.java by typing
following at command prompt
– javac MathServiceClient.java
• Execute Client by typing following at
command prompt
– java MathServiceClient
• Output should be
MathService.getSum(5,6) = Sum of 5 and 6 is 11
11