Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Creating Web Services Presented by Ashraf Memon Hands-on Ghulam Memon, Longjiang Ding.

Similar presentations


Presentation on theme: "1 Creating Web Services Presented by Ashraf Memon Hands-on Ghulam Memon, Longjiang Ding."— Presentation transcript:

1 1 Creating Web Services Presented by Ashraf Memon Hands-on Ghulam Memon, Longjiang Ding

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

3 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 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 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 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 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 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 Servicehttp://localhost/axis/

9 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 10 Create Web Service to Access ASCII fileCreate Web Service to Access ASCII file Next Chapter


Download ppt "1 Creating Web Services Presented by Ashraf Memon Hands-on Ghulam Memon, Longjiang Ding."

Similar presentations


Ads by Google