Download presentation
Presentation is loading. Please wait.
Published byBrittany Nash Modified over 8 years ago
1
Net-centric Computing Web Services
2
Lecture Outline What is Web Service Web Service Architecture Creating and using Java Web Services Apache Axis Simple Examples
3
What is a Web Service A web service is a network accessible interface to application functionality, built using standard Internet technologies. Clients of web services do NOT need to know how it is implemented. Application client Application code Network Web Service
4
A more detailed definition 4University of Pennsylvania "A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-readable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web- related standards." http://www.w3.org/TR/ws-arch/
5
Servlets/CGI vs Web Services Browser Web Server HTTP GET/POST DB JDBC Web Server DB JDBC Browser Web Server SOAP GUI Client SOAP WSDL
6
Web Services Architecture There are two ways we can view Web Services architecture 1. Web Service Roles 2. Web Service Protocol Stack
7
Web Service Roles There are three major roles Service Registry (UDDI) Service Requestor Service Provider 2) Discover services (WSDL) 3) Invoke service (SOAP) Provider of the Web ServiceConsumer of the Web Service Logically Centralized directory of services 1) Register service (WSDL)
8
Web Service Protocol Stack Discovery UDDI Description WSDL XML Messaging XML-RPC,SOAP,XMLL Transport HTTP,SMTP,FTP Responsible for centralizing services Responsible for transporting messages Responsible for describing the public interface to a specific web service Responsible for encoding messages in common XML format
9
Web Services Standard Prorocols WSDL – Web Service Description Language Describes how the service will be used Guidelines for constructing SOAP messages SOAP – Simple Object Access Protocol XML message format between client and service UDDI – Universal Description, Discovery and Integration protocol A protocol for publishing web service descriptions
10
SOAP Message Envelope is like a wrapper for content Header is a optional element that could contain control information Body element includes requests and responses Body element will include a Fault element in the event of an error SOAP Message Envelope Header Body
11
Sample SOAP Request <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns1:sayHello xmlns:ns1="http://agram.com/"> Java
12
Sample SOAP Response <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns1:sayHelloReponse xmlns:ns1="http://agram.com/"> Hello Java
13
WSDL major elements Has 6 major elements 1. definitions – defines the name of the web service 2. types – describes all the data types that will be transmitted 3. message – defines the name of the message that will be transmitted 4. portType – defines the operations 5. binding – defines how the message will be transmitted 6. service – defines where the service is located
14
Development plan for Service Requestor 1) Find web service via UDDI 2) Retrieve service description file 3) Create XML-RPC or SOAP client 4) Invoke remote service
15
Development plan for Service Provider 1) Create the core functionality 2) Create XML-RPC or SOAP service wrapper 3) Create service description file 4) Deploy service 5) Register new service via UDDI
16
Tools for developing Services Apache Axis Sun Web Services for Java SOAP Lite for Pearl.NET tools from MS gSOAP for C++ …
17
Sending requests, getting results SOAP-awareServlet (e.g. Apache Axis) SOAP-awareServlet Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” Any class processing the incoming requests (“business logic” HTTP Server (e.g. Apache Tomcat) Servlet engine Apache Tomcat vs Axis
18
Get the Code Axis Web site: http://ws.apache.org/axis/ http://ws.apache.org/axis/ Select downloads. Get release 1.4 From the mirror site, download the.zip. Right click to save to desktop. .tar.gz is for the Unix/Linux tar utility. Right click the axis-1_4 zip folder icon to extract the files.
19
Installing Apache Axis 2) Deploy Axis Server in the Tomcat 4.X server a) Copy Axis Web application (webapps/axis directory) to $TOMCAT_HOME/webapps b) Add the following libraries (available under …/axis/WEB-INF/lib folder) into your CLASSPATH environment variable: axis.jar, commons-discovery.jar, commons- logging.jar, jaxrpc.jar, log4j-1.2.8.jar, saar.jar, wsdl4j-1.5.1.jar
20
CLASSPATH example set AXIS_HOME=C:\jakarta-tomcat-4.0.6\webapps\axis set AXIS_LIB=%AXIS_HOME%\WEB-INF\lib set AXIS_CP=.;%AXIS_CP%;%AXIS_LIB%\axis.jar; %AXIS_LIB%\commons-discovery.jar; %AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar; %AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\wsdl4j.jar set classpath=%AXIS_CP%
21
Validating the Installation 1) Start the Tomcat Web Server 2) Goto http://localhost:8080/axis/http://localhost:8080/axis/ - you should be able to see Apache-Axis start page - if you did not, then the axis is not correctly installed or the web server is not running 3) Goto http://localhost:8080/axis/happyaxis.jsphttp://localhost:8080/axis/happyaxis.jsp - this test page verifies whether all the needed and optional libraries are present. - Axis will not perform properly until all the needed libraries are present.
22
Creating a Web Service in Java Typical steps: 1. Create the application 2. Generate WSDL document using some Web Service tool 3. Deploy Web Service to a Web Server 4. Generate client stubs from WSDL 5. Create client application Then publish, discover and use web service
23
Develop a service Step 1 – Write a Java Class public class AdderImpl implements Adder { public int add(int x, int y) throws RemoteException { return x + y; }
24
public interface Adder { int add (int x, int y); } public class AdderImpl implements Adder { public int add(int x, int y) throws RemoteException { return x + y; } Adder.java AdderImpl.java
25
Develop a service Step 2 - Deploy to the SOAP engine Create the deployment descriptor (*.wsdd) <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
26
Develop a service Step 2 - Deploy to the SOAP engine Copy the Java Class to the Web Server Start the Web Server Deploy java org.apache.axis.client.AdminClient *.wsdd
27
Develop a service Step 3 - Check Check (List all services) http://localhost:8080/axis/servlet/AxisServlet
28
Consume a service Step 1 – Get the WSDL file of the service Java2WSDL (usage example) java org.apache.axis.wsdl.Java2WSDL -o adder.wsdl -l http://localhost:8080/axis/services/adderService -n http://cop4991/adder adderImpl We use this tool because the service is built by ourselves (we have the Java Class) output location namespace class name
29
Consume a service Step 2 – Generate the Client Stub WSDL2Java (usage example) java org.apache.axis.wsdl.WSDL2Java myecho.wsdl 4 files will be generated AdderImpl.java AdderImplService.java AdderImplServiceLocator.java AdderServiceSoapBindingStub.java interface Service factory Service Binding stub
30
Consume a service Step 3 – Write the Client Program … // Make a service AdderImplService adderService = new AdderImplServiceLocator(); // Now use the service to get a stub AdderImpl adder = adderService.getadderService(); // Make the actual call int sum = adder.add(10,9); …
31
public class AdderClient{ public static void main(String[] args){ try{ //Make a service instance AdderImplService adderService = new AdderImplServiceLocator(); //Now use the service to get a stub AdderImpl adder = adderService.getadderService(); //Make the actual call int sum = adder.add(10,9); System.out.println("the sum is: "+sum); }catch(Exception e){e.printStackTrace();} } AdderClient.java
32
Static Stub Client Our client is static Tightly bound to generated stub Can only use one service Dynamic Clients Use WSIF (Web Service Invocation Framework) instead
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.