Download presentation
Presentation is loading. Please wait.
1
Lecture 10: Web Services
2
Outline Overview of Web Services Create a Web Service with Sun J2EE (JAX-RPC)
3
What is a Web Service? A web service is a network accessible interface to application programs, built using standard Internet technologies. Clients of web services do NOT need to know how it is implemented. Application client Application program Network Web Service
4
Web Service Architecture Service provider Service broker Service requestor publish (WSDL) find (UDDI) bind (SOAP) "server" "client""naming service"
5
Web Service Technology Stack Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Client Proxy = Stub, Server Proxy = Tie publish WSDL URIs
6
Step 1. Write Web Service Method Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Client Proxy = Stub, Server Proxy = Tie publish WSDL URIs
7
Step 2. Describe Web Service using WSDL Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy WSDL can be automatically generated publish WSDL URIs
8
Step 3. Deploy Service at Server Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Tie will be created, service location stored in WSDL publish WSDL URIs
9
Step 4. Publish Service Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Client can locate the service querying UDDI publish WSDL URIs
10
Step 5. Generate Client Proxy Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy publish WSDL URIs Stubs can be generated from WSDL automatically
11
Step 6. Write Client to Invoke Proxy Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy publish Stubs can be generated from WSDL automatically
12
Step 7. Execute Client Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy publish Client invokes service (almost) like a local method
13
JAX-RPC JAX-RPC = Java Web Services Architecture Sun's solution for writing Web Services and Web Service clients Example: "HelloWorld" Service
14
Step 1. Write Web Service Method Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Client Proxy = Stub, Server Proxy = Tie publish WSDL URIs
15
Service Interface package iis; import java.rmi.Remote; import java.rmi.RemoteException; public interface HelloIF extends Remote { public String sayHello(String s) throws RemoteException; } Web Service Interface derived from class Remote Methods required to throw RemoteException
16
Service Implementation package iis; public class HelloImpl implements HelloIF { public String message ="Hello"; public String sayHello(String s) throws RemoteException { return message + s; } } Compile the classes: javac HelloIF.java HelloImpl.java
17
Step 2. Describe Web Service using WSDL Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy WSDL can be automatically generated publish WSDL URIs
18
Configuration File All relevant information on Web Service <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config"> <service name="HelloWorldService" targetNamespace="http://lsirwww.epfl.ch/" typeNamespace="http://lsirwww.epfl.ch/" packageName="iis">
19
Generate WSDL Automatically derived from Interface and Configuration File wscompile -define -mapping build/mapping.xml -d build -nd build -classpath build config.xml Deploytool will need information from mapping.xml
20
Structure of WSDL definition of parameter data types in XML Schema (optional) definition of a message (request, reply) definition of an operation (request – reply pair) definition of a protocol binding (typically SOAP) definition of a port (an Internet address) abstract concrete
21
Messages Provides message names and passing of parameters
22
Ports Define message sequences corresponding to a service invocation
23
Protocol Binding Implement abstract messages according to SOAP protocol
24
Sample Soap Message Hello World! http://www.w3.org/2002/12/soap-envelope/role/next SOAP client SOAP server Request message Response message
25
Service Access Location not known before deployment
26
Step 3. Deploy Service at Server Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Tie will be created, service location stored in WSDL publish WSDL URIs
27
Deploy Service Web service tie is implemented as servlet Servlet is a Java application that can interact with Web Server (also JSPs are implemented as servlets!) Tie automatically generated at deployment
28
WAR file and Context Root WAR file is archive collecting all needed files (like JAR) Contect Root is location on Web Server
29
Provide WSDL File As generated before
30
Provide Service Implementation Note: WSDL does not know about the implementation!
31
Service Access Note: Multiple Ports may have been provided in WSDL!
32
WSDL after Deployment This can be published via UDDI
33
Step 4. Publish Service Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy Client can locate the service querying UDDI publish WSDL URIs
34
UDDI
35
Step 5. Generate Client Proxy Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy publish WSDL URIs Stubs can be generated from WSDL automatically
36
Generate Stubs Client Configuration File <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config"> Automatically created using WSDL and client configuration file wscompile -gen:client -d build -classpath build config-client.xml
37
Step 6. Write Client to Invoke Proxy Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy publish Stubs can be generated from WSDL automatically
38
Client Application package iis; import javax.xml.rpc.Stub; public class HelloClient { private String endpointAddress; public static void main(String[] args) { try { Stub stub = createProxy(); stub._setProperty (javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, args[0]); HelloIF hello = (HelloIF)stub; System.out.println(hello.sayHello(args[1])); } catch (Exception ex) { ex.printStackTrace(); } see next slide WS address parameter
39
Creating Proxy (Stub) private static Stub createProxy() { return (Stub) (new HelloWorldService_Impl().getHelloIFPort()); } attaching _Impl to the service name is an implementation-specific naming convention
40
Compiling and Packaging compile javac –classpath system_jars:server_class_files: stub_class_files HelloClient.java package jar cvf hello-client.jar all_client_class_files:all_server_class_files Note: in the exercise the commands are automated by using the asant scripting utility provided by Sun J2EE
41
Step 7. Execute Client Discovery Description Packaging Transport Network shopping web service? WSDL URIs Web Service Client Web Service UDDI Proxy WSDL SOAP pkg request SOAP pkg response Proxy publish Client invokes service (almost) like a local method
42
Invoke Client java –classpath hello-client.jar:jwsdp-jars hello.HelloClient "Hello World!" Generated at Server – Displayed at Client
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.