0% found this document useful (0 votes)
91 views10 pages

CSIG WS Creating Web Services

The document discusses how to create web services in Java by writing service classes, generating WSDL files using Apache Axis, deploying the services on a Tomcat server, and generating client code to test the services by making requests and receiving responses. It provides step-by-step instructions for creating a math web service that can add two numbers by writing a Java class, deploying it with Axis, and testing it with a client.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views10 pages

CSIG WS Creating Web Services

The document discusses how to create web services in Java by writing service classes, generating WSDL files using Apache Axis, deploying the services on a Tomcat server, and generating client code to test the services by making requests and receiving responses. It provides step-by-step instructions for creating a math web service that can add two numbers by writing a Java class, deploying it with Axis, and testing it with a client.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

1

Creating Web Services

Presented by
Ashraf Memon

Hands-on
Ashraf Memon, Ghulam Memon
2

Overview

• Writing service classes in Java


• Generating service
• Deploying services with Apache
Axis
• Generating client files and testing
them
3

Writing service classes in Java

• Service classes are similar to


normal Java classes
– Any existing Java Class can be
converted into web service
– Keep the input/output interface
simple (primitive types such as
String, int, boolean, double)
4

Writing service classes in Java


• 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;
5

Writing service classes in Java


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; Math sampleProgram = new Math();
String reply = sampleProgram.getSum(3,4);
System.out.println(reply);
}
}
6

Generating Service
• Navigate to solutions directory c:\data\csig05\ws\solutions
• Open command prompt by right clicking on the math
directory and selecting “Command Prompt Here”
• Change to math directory by typing following at the
command prompt
cd math
• Compile Math.java file by typing following at command
prompt
javac Math.java
• Run program by typing following at command prompt
java Math
• Output should be
Sum of 3 and 4 is 7
• Type exit on the command prompt to quit
7

Deploying services with Apache Axis

• Copy generated class file to


C:\tools\tomcat4.1\webapps\axis\WEB-INF\classes\

• Open using any text editor deployMath.wsdd from


C:\tools\tomcat4.1\webapps\axis\WEB-INF\classes\

• Get yourself familiar with the contents


8

Deploying services with Apache Axis

• Navigate to C:\tools\tomcat4.1\webapps\axis\WEB-INF\
• Open command prompt by right clicking on the classes
directory and selecting “Command Prompt Here”
• Change to classes directory by typing following at the
command prompt
cd classes
• Set classpath by typing classpath.bat on the command
prompt
• Execute deployment descriptor by typing deploy.bat
deployMath.wsdd at command prompt
• This will deploy math webservice on Axis SOAP Server
• Test it by going to http://localhost/axis/ and navigating
to Math Service
9

Generating client files and testing them


• Change directory to c:\data\csig05\ws\solutions\math
by typing “cd c:\data\csig05\ws\solutions\math” on the
command prompt
• Compile MathServiceClient.java by typing following on
the command prompt
javac MathServiceClient.java
• Execute Client by typing following on the command
prompt
java MathServiceClient
• Output should be
MathService.getSum(100,333) = Sum of 100 and 333 is
433
10

Next Chapter

• Create Web Service to Access


ASCII file

You might also like