Download presentation
Presentation is loading. Please wait.
1
3b.1 Web Services Part II Implementation details ITCS 4010 Grid Computing, 2005, UNC-Charlotte, B. Wilkinson, slides 3b version 0.1.
2
3b.2 What we know so far Basis parts of a service-oriented architecture: –The service provider, (server) –service requestor (client), –a service registry. If registry used, web services generally use a UDDI registry, which itself is a web service. SOAP used as the messaging protocol carrying XML documents and using an HTTP transport. WSDL, an XML language, is used to describe the web service.
3
3b.3 After registry populated with web service entries, client can access registry to find out whether desired web service exists in registry and if so where it is located. Registry responds with identification of server capable of satisfying needs of client. Then, client can access server for web service interface. Server responds with an WSDL document describing the service and how to access it. Client can then send web service a request requesting an operation. Result of operation returned in a message from the web service. All messages are SOAP messages.
4
3b.4 Web Services From http://www.globus.org
5
3b.5 Web Service Container Web Services generally “hosted” in a web service container – software environment that provides communication mechanisms to and from the web services and clients.
6
3b.6 Several possible software environments designed for web services: Apache Axis (Apache eXtensible Interaction System) IBM Websphere Microsoft.NET J2EE (Java 2 Enterprise Edition) server container also a candidate for hosting web services especially in enterprise (business) applications.
7
3b.7 Apache Axis available for free down (Windows or Linux): http://ws.apache.org/axis Used for the first web service assignment in course. Apache Axis requires an application server. –Can be installed on top of a servlet engine such as Apache Jakarta Tomcat. –However, could be installed on top of a fully- fleldged J2EE server.
8
3b.8 Web service environment Web service container Web services Client Will use an Application server (servlet engine) (e.g. Apache Jakara Tomcat ) (e.g. Apache Axis) Network SOAP messages carried with HTTP transport
9
3b.9 Client-Service Implementation In the implementation, it is convenient to use stubs - java classes suitable for web services defined with WSDL.
10
3b.10 Client Stub Between client code and the network is a client stub, sometimes called client proxy. The client stub is responsible for taking a request from the client and converting the request into a SOAP request on the network - marshalling. Also responsible for receiving SOAP responses on network and converting to a suitable form for client.
11
3b.11 Server Stub Between the service and the network is a server stub, sometimes called a skeleton. Responsible for receiving a SOAP request from the client stub and converting it into a suitable form for the service -unmarshalling. Also converts the response from the service into a SOAP message for the client stub.
12
3b.12 Web Service Application
13
3b.13 Steps Client calls client stub. SOAP request sent across network Server stub receives request and sends request to service Service send result to serve stub Server stub sends result across network to client stub. Client stub sends result to client.
14
3b.14 Web Service Application Call client stub SOAP request Request service Result returned SOAP response Client receives result
15
3b.15 Web Service Description Recall use an Interface Description language (IDL) called WSDL to formally describe a service, what is does, how it is accessed, etc.
16
3b.16 Web Service Definition Language (WSDL) A W3C standard XML document that describes three fundamental properties of a service: What it is - operations (methods) it provides. How it is accessed - data format, protocols. Where it is located - protocol specific network address.
17
3b.17 Math Web service For concreteness, let us consider the web service used in assignment 1. A simple version is: public class MyMath { public int squared(int x) { return x * x; }
18
3b.18 Question What does this service do? Answer
19
3b.19 Elements of a WSDL document
20
3b.20 Parts of a WSDL Document Root definitions - namespaces portType definitions - abstract definition of service Message definitions - parameters in method signature Type definitions - data types Binding definitions - to protocols i.e. SOAP over HTTP Service definitions - where service is, ports
21
3b.21 WSDL file for math web service <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/>
22
3b.22 <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> Namespaces Message definitions portType Bindings Service definitions
23
3b.23 Root Definitions Namespaces <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
24
3b.24 portType Describes “What” - an abstract definition of service operation. Uses the elements: message definitions - a set of parameters referred to by method signature, decomposed into parts type definitions - defines all data types used
25
3b.25 portType Definitions
26
3b.26 Message Definitions Standard XML integer type – no special types in this example
27
3b.27 Binding Describes “how” the elements in abstract interface (portType) are converted in actual data representations and protocols e.g. SOAP over HTTP.
28
3b.28 <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> Binding definitions
29
3b.29 port and service Describe “where” service is. port - describes how a binding is deployed at the endpoint of a network service - a named collection of ports
30
3b.30 Port/Service Definitions Where math service is
31
3b.31 Build and deploy a web service Several ways to create a web service within a container and have accessible by clients. Fundamental service components to build are: Web service code WDSL service description file Web service stub and client components: Client stub Client code
32
3b.32 What to create to deploy and test a service Client Client stubServer stub Service ContainerClient Applications WSDL service description Web service code WDSL service description file Web service stub Client stub Client code
33
3b.33 In the following, we will assume that we are using Apache Axis, which has several tools for building and deploying a web service.
34
3b.34 Java Web Service (JWS) deployment facility Absolute simplest way in Axis to deplore a web service: First, web service class file with methods created. Then file simply renamed as.jws and dropped into a specific directory that axis expects.jws services to be. Service code with.jws extension interpreted as a web service..jws file automatically compiled if necessary when service called. All public methods in the service code available and accessible as service operations. Simple and used in assignment 1 but has limitations. – Restrictions include using globally known data types, i.e., data types known to Axis. If not part of standard type mappings, one must declare mappings.
35
3b.35 jws facility Could actually use web service after deployment with JWS without using a WSDL file nor stubs. One could just use service URL, which would have a.jws extension. Client and service need code to make SOAP calls. However, one would normally create a WSDL file and the stubs, and get the stubs to handle the SOAP. That is done in assignment 1.
36
3b.36 Web Service Deployment Descriptor (WSDD) WSDD is an XML language used to describe how to deploy a service. Provides for greater flexibility than with jws “instant” deployment facility.
37
3b.37 WSDD file for MyService <deployment xmlns="http://xml.apache.org/axis/wsdd/ xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
38
3b.38 Deployment with WSDD file Once WSDD file deploy.wsdd created, can deploy with Axis tool AdminClient: java org.apache.axis.client.AdminClient deploy.wsdd This method not use in assignment 1.
39
3b.39 Creating WSDL file Several ways this can be approached: Create service code first and use as basis for WSDL file or Create WSDL file first and use this as basis for the service code Second method probably better from a Software Engineering perspective, but will look at both.
40
3b.40 WSDL from Service Code Java2WSDL Tool Axis Java2WSDL program generates WSDL file (and its schema) from service code. Program has number of flags including to specify: Name of the output WSDL file (-o flag) Location (URL) of the service (-l flag) Namespace of WSDL file (-n flag) Mapping from package to namespace (-p flag)
41
3b.41 Example Suppose we have interface MyMath.java for our service as: public interface MyMath { public int squared(int x) } To create WDSL file MyMath.wsdl from this interface file, we might issue command: % java org.apache.axis.wsdl.Java2WSDL -o MyMath.wsdl -l "http://localhost:8080/axis/services/MyMath" MyMath
42
3b.42 <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Apache Axis version: 1.2 Built on May 03, 2005 (02:20:24 EDT)--> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/ encoding/" namespace="http://DefaultNamespace" use="encoded"/> WSDL file created
43
3b.43 Stubs from WSDL If we have WSDL document for service, can use tools to generate client and server stubs: –Axis WSDL2Java program generates stubs for use on client and server –Example of this in assignment 1.
44
3b.44 Axis tool WSDL2Java Has a number of flags, including to specify: Root directory of output files (-o flag) Create server-side bindings for web service (-s flag) Deploy server stub (skeleton) or deploy implementation( -S true/false) Add scope to deploy.wsdd, "Application", Request" or "Session" (-d flag) Mapping all namespace in WSDL document to same Java package name (-p flag)
45
3b.45 WSDL2Java Example Suppose we have wsdl file MyMath.wsdl for our service. Invoke as: java org.apache.axis.wsdl.WSDL2Java -o. -d Session -s -S true -p localhost.axis.yourusername.MyMath_jws MyMath.wsdl
46
3b.46 WSDL from Running Service In Axis, can generate WSDL document directly from a running deployed service. Add ?wsdl onto service URL. Example If MyMath already deployed, say with the jws deployment facility, then setting browser to point to: http://yourserver.yourdomain.edu:8080/axis/…/MyMath.jws?wsdl will display the WSDL file. Port number (8080) may be different in an actual system.
47
3b.47 Putting all together Can couple ?wsdl method with invoking WSDL2Java to create required files with composite command: java -classpath $AXISCLASSPATH org.apache.axis.wsdl.WSDL2Java http://localhost:8080/axis/yourusername/MyMath.jws?wsdl Will generate a directory structure.../… /MyMath.jws/ and four files within MyMath.jws: MyMath.java -- source for the Java interface for MyMath class. MyMathService.java - source for Java interface. MyMathServiceLocator.java - source for Java class MyMathServiceLocator. MyMathSoapBindingStub.java - source for Java class MyMathSoapBindingStub. These files need to be compiled with, for example, the command: javac -classpath $AXISCLASSPATH localhost/axis/yourusername/MyMath_jws/*.java
48
3b.48 Client side programming Once deployed service, want to use it or allow others to use it. Depending upon details of deployed service and web service environment, a simple Java program can be used to access service such as: import localhost.axis.yourusername.MyMath_jws.MyMathServiceLocator; import localhost.axis.yourusername.MyMath_jws.MyMathService; import localhost.axis.yourusername.MyMath_jws.MyMath; public class MyMathClient { public static void main(String args[]) throws Exception { MyMathService service = new MyMathServiceLocator(); MyMath myMath = service.getMyMath(); int x = (new Integer(args[0])).intValue(); System.out.println("The square of " + args[0] + " is " + myMath.squared(x)); }
49
3b.49 Quiz What is Apache Axis? (a) A tool used by American Indians (b) A hosting environment for web services (c) A compiler (d) A type of make tool
50
3b.50 Which of the following contains all the services that have been deployed? (a) Class (b) Shell (c) Container (d) Object
51
3b.51 What is a client stub? (a) A way of offending a customer (b) Code between the client code and the network (c) A document that explains the client code (d) None of the other answers
52
3b.52 More information on Axis http://xml.apache.org/axis
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.