Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility.

Similar presentations


Presentation on theme: "Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility."— Presentation transcript:

1 Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility to provide the features across different platforms that are developed using different languages, and can be used by any remote application, over the internet and avoid securely restrictions.

2 SOAP web services SOAP is essentially an XML-based protocol for invoking remote methods.(verb oriented vs. noun oriented REST WS) Communication between the service and the application is through a standard format called XML (eXtensible Markup Language) which is universal and is accepted on any platform across the distributed network.

3 SOAP (Simple Object Access Protocol) SOAP is a protocol based on HTTP protocol that by means of which Web Services is enabled; it is the format that is acclaimed universally due to its nature of standardization and rules that it implements.. http://cwiki.apache.org/GMOxDOC20/sim ple-web-service-with-jax-ws.htmlhttp://cwiki.apache.org/GMOxDOC20/sim ple-web-service-with-jax-ws.html

4 UDDI (Universal Discription, Discovery and Integration): UDDI is specifically a governing body that monitors the publication and discovery of the web services implementation with respect to message communication between the application and also at the enterprise level. Web service is deployed on Web server (Apache Tomcat, IIS) or Application server(Java EE, Glassfish, WebLogic)

5

6 Simple calculation web service (add, subtract) @webservice

7 WSDL (Web Service Description Language): WSDL is an XML-based language that describes the interface to SOAP services It consists of the description about the web service, which is basically a file with.wsdl extension that you can find in your application folder.

8 WSDL basics: written in XML, describe web services, locate web services WSDL structure data types used by the WS messages (I/O parameters) set of operations(Interface) communication protocols used by the WS

9 WSDL structure (types)...

10 WSDL structure (message)

11 WSDL structure (portType)

12 Simple Object Access Protocol: structure SOAP <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap- encoding">......

13 SOAP structure (request) <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soapenvelope" xmlns:axis="http://ws.apache.org/axis2"> 45 12

14 SOAP structure (response) <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soapenvelope" xmlns:axis="http://ws.apache.org/axis2"> 57

15 A complete example of JAX-WS Webmethod int add(int a, int b), the SOAP request and response for this method might look like the following: SOAP request 1 2

16 SOAP response 3

17 names a, specifies a (URI) at which it is available and refers to a binding for the port specifies the style of interaction (e.g. RPC) transport protocol used (e.g. HTTP) s defined along with encodingStyle for their and specifies a set of named s which refer to the s used by each for and a describes a one-way message (request or response) consists of a number of s referring to parameters or return values, each of which has a type (e.g. xsd:string) describes all data types used between client and server (XML schema is default type system)

18 Add service WSDL

19

20 Service definition

21 Calculator interface The Calculator interface defines the Service Endpoint Interface (SEI) for the Web Service. http://cwiki.apache.org/GMOxDOC20/simple-web- service-with-jax-ws.html http://cwiki.apache.org/GMOxDOC20/simple-web- service-with-jax-ws.html Calculator.java package org.apache.geronimo.samples.jws; import javax.jws.* @WebService(name="CalculatorPortType", targetNamespace = "http://jws.samples.geronimo.apache.org") public interface Calculator { @WebMethod public int add(@WebParam(name = "value1") int value1, @WebParam(name = "value2") int value2);}

22 The CalculatorService class implements the Web Service business logic. It implements all the methods defined in the SEI. The class does not need to implement the Calculator interface but must reference it through the @WebService.endpointInterface annotation. This class will be exposed as a Servlet through web.xml file even though it does not extend the javax.servlet.Servlet class. The context variable marked with the @Resource annotation will be injected at runtime. The WebServiceContext can be used to obtain the message context and security information relative to the call.

23 CalculatorService.java package org.apache.geronimo.samples.jws; import javax.annotation.Resource;import javax.jws.WebService; import javax.xml.ws.WebServiceContext; @WebService(serviceName = "Calculator", portName="CalculatorPort", endpointInterface = "org.apache.geronimo.samples.jws.Calculator", targetNamespace = "http://jws.samples.geronimo.apache.org", wsdlLocation = "WEB-INF/wsdl/CalculatorService.wsdl") public class CalculatorService implements Calculator @Resource private WebServiceContext context; public int add(int value1, int value2) { System.out.println("User Principal: " + context.getUserPrincipal()); return value1 + value2; }} The web.xml descriptor is used to deploy the Web Service. If the web.xml descriptor is not provided, it will be automatically generated during deployment.

24 JSP-based JAX-WS client The add.jsp is a basic client for the CalculatorService Web Service. Apache Geronimo Sample Application - JAX-WS Calculator

25 Value 1: Value 2: <% String value1 = request.getParameter( "value1" ); String value2 = request.getParameter( "value2" ); if (value1 != null && value1.trim().length() > 0 && value2 != null && value2.trim().length() > 0) { try { int v1 = Integer.parseInt(value1); int v2 = Integer.parseInt(value2); InitialContext ctx = new InitialContext(); Service service = (Service)ctx.lookup("java:comp/env/services/Calculator"); Calculator calc = service.getPort(Calculator.class); int sum = calc.add(v1, v2); out.println("Result: " + v1 + " + " + v2 + " = " + sum); } catch ( Exception e ) { out.println("Error: " + e.getMessage()); } ); }%>

26


Download ppt "Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility."

Similar presentations


Ads by Google