creating web services presented by ashraf memon presented by ashraf memon

11
Creating Web Services Presented by Ashraf Memon

Upload: elwin-moody

Post on 18-Jan-2018

220 views

Category:

Documents


0 download

DESCRIPTION

3 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.

TRANSCRIPT

Page 1: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

Creating Web Services

Presented byAshraf Memon

Page 2: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

2

Overview

• Writing service classes in Java• Generating service• Deploying services with Apache Axis• Generating client files and testing them

Page 3: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

3

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.

Page 4: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

4

Writing service classes in Java (contd)

• Class contains 1 function which performs addition.

• Function signature ispublic String sum(int num1, int num2)

• Function implementation isint answer = num1+num2;return "Sum of "+num1+" and "+num2+" is "+answer;

• Complete class code follows on next slide.

Page 5: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

5

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;

Page 6: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

6

Writing service classes in Java (contd)

Math sampleProgram = new Math(); String reply = sampleProgram.getSum(3,4); System.out.println(reply); }}

Page 7: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

7

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 promptjavac Math.java

• Run program by typing following at command prompt

java Math

Page 8: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

8

Generating Service (contd)

• Output should beSum of 3 and 4 is 7

Page 9: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

9

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.

Page 10: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

10

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.

Page 11: Creating Web Services Presented by Ashraf Memon Presented by Ashraf Memon

11

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 beMathService.getSum(5,6) = Sum of 5 and 6 is 11