Module 12 Web Service Model Objectives Describe the role of web services List the specifications used to make web services platform independent Describe the Java APIs used for XML processing and web services 318 Ω Omega Ω 1
Understanding Web Services The W3C defines a web service as a software system designed to support interoperable machine-to-machine interaction over a network. Web services are: Platform independent Designed to leverage existing technologies Interoperable with disparate programming languages 319 Ω Omega Ω Web Services as Remote Components Web services provide a mechanism to remotely execute a business operation. Web services provide remote execution similar to: CORBA RMI RPC DCOM Web services differ from these technologies by leveraging HTTP and XML, both of which are well supported by libraries in almost every programming language, as a transport and payload standard respectively. 320 Ω Omega Ω 2
Web Services Compared to Remote EJBs A web service consists of: A registry for publishing and looking up web services known as a Universal Description, Discovery and Integration (UDDI). If the client already knows the location of the desired service, the registry can be bypassed. A transport protocol used to invoke operations, pass arguments, and receive return values. In Remote EJBs this can be the Internet Inter-Orb Protocol (IIOP). In web services HTTP is used. A sequence of data transferred between the client and server. Remote session beans use a serialized object while web services use XML. 321 Ω Omega Ω The Need for Interoperability Web services are designed to be platform and language neutral, to make web services effective they must: Support clients regardless of platform or language Able to be implemented in any language regardless of the platform Just using HTTP as a transport protocol and XML as a data format does not provide a high level of interoperability. To be interoperable: The methods and headers used in the HTTP transport protocol must be standardized. The format of XML messages must known. 322 Ω Omega Ω 3
Interoperability Standards Extensible Markup Language (XML) A W3C standard designed to store data in a format both readable to humans and easily parsed by machines. Hyper Text Transfer Protocol (HTTP) A W3C standard for short lived data communication. Universal Description, Discovery and Integration (UDDI) A publish and lookup standard sponsored by OASIS. 323 Ω Omega Ω Interoperability Standards Simple Object Access Protocol (SOAP) A W3C standard that enforces a more defined structure upon the XML formatted messages used in web services. Web Services Description Language (WSDL) A proposed W3C standard that defines the functionality of a web service. Similar in purpose to the business interface of a session EJB but formatted in XML. Web Services Interoperability (WS-I) A profile that mandates the use of certain specification such as SOAP and WSDL, placing addition restrictions on them as needed, to provide interoperable web services. 324 Ω Omega Ω 4
Java APIs Related to XML and Web Services Java DOM (JDOM) Java API for XML Processing (JAXP) Java Architecture for XML Binding (JAXB) Java API for XML-based Remote Process Communications (JAX-RPC) Java API for XML Registries (JAXR) SOAP With Attachments API for Java (SAAJ) Java API for XML Web Services (JAX-WS) 325 Ω Omega Ω The SAAJ API The SAAJ API allows clients to use web services without having to concern themselves with the XML parser or the transport protocol used. While considered a higher level API then JAXP, it still requires XML and WSDL knowledge. MessageFactory msgfactory = MessageFactory.newInstance(); SOAPMessage message = msgfactory.createmessage(); SOAPHeader header = message.getsoapheader(); header.detachnode(); SOAPBody body = message.getsoapbody(); QName bodyname = new QName("http://sample/","getGreeting", "ns1"); SOAPBodyElement requestbodyelement = body.addbodyelement(bodyname); QName name = new QName("arg0"); SOAPElement symbol = requestbodyelement.addchildelement(name); 326 Ω Omega Ω 5
symbol.addtextnode("duke"); SOAPConnectionFactory connfactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = connfactory.createconnection(); String endpoint="http://localhost:8080/webservice/sayhelloservice"; SOAPMessage response = connection.call(message, endpoint); connection.close(); SOAPBody soapbody = response.getsoapbody(); SOAPBodyElement getgreetingresponseelement =(SOAPBodyElement) soapbody.getchildelements().next(); SOAPBodyElement returnelement = (SOAPBodyElement) getgreetingresponseelement.getchildelements().next(); System.out.print("The response was: +returnelement.getvalue()); 327 Ω Omega Ω The JAX-WS API The JAX-WS API is the highest level Java API for web services. JAX-WS: Replaces JAX-RPC Requires little to no XML or WSDL knowledge for basic web services Uses JAXB to specify how Java and XML data types are mapped Uses SAAJ to send, receive, and parse SOAP messages 328 Ω Omega Ω 6