Top Banner
Web Services: JAX-RPC, WSDL, XML Schema, and SOAP CSI 3140 WWW Structures, Techniques and Standards
76
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • Web Services:JAX-RPC, WSDL, XML Schema, and SOAPCSI 3140WWW Structures, Techniques and Standards

  • Web Services ConceptsA web application uses Web technologies to provide functionality to an end userA web service uses Web technologies to provide functionality to another software application

  • Web Services ConceptsStandard web services technologies:Communication via SOAP XML vocabulary documents over HTTPOperations of web service defined by Web Services Definition Language (WSDL) XML vocabularyData within WSDL defined using XML Schema

  • Web Services ConceptsHigher-level APIs are often used to automatically generate web services client and server communication softwareWe will use the Java API for XML-based Remote Procedure Call (JAX-RPC)Microsoft .NET framework is one popular alternative to JAX-RPC

  • Web Services ConceptsWeb services conceptually are just specialized web applications:ClientServer(Java servlet)HTTP request (SOAP body)HTTP response (SOAP body)

  • Web Services ConceptsBody of web services request is analogous to calling a methodOperation name (like method name)Input parameter valuesInput parameternames

  • Web Services ConceptsBody of web services response is analogous to value returned by a methodReturn value data typeReturnvalue

  • Web Services ConceptsWSDL defines web serviceOperationsParametersReturn valuesCommunication protocolsBasically an API for the web serviceFacilitates automated client/server software generation

  • Web Services ConceptsPortions of NWS WSDLOperation nameInputparamsReturntypeData typesdefined usingXML Schema

  • Web Services ConceptsJava Web Services Developer Pack (JWSDP) wscompile tool can implement a Java API from a WSDL Classes and methodsgenerated by wscompileThis method automatically handles SOAP request and response

  • Web Services ConceptsWriting the server for a web service with JWSDP:Write a Java interface defining the APIImplement the interfaceJWSDP generatesSOAP and communication handling classesWSDL

  • Web Services ConceptsExample Java interface

  • Web Services ConceptsExample implementation

  • Web Services ExamplesTons of WS available on the internet.http://www.webservicex.net as a good collectionGeo IP: http://www.webservicex.net/geoipservice.asmx?op=GetGeoIPWhois: http://www.webservicex.net/whois.asmx?op=GetWhoISSMS: http://www.webservicex.net/sendsmsworld.asmxEtc..Google:AmazonS3

  • JWSDP: ServerApplication: currency converterThree operations:fromDollarsfromEurosfromYenInput: value in specified currencyOutput: object containing input value and equivalent values in other two currencies

  • JWSDP: ServerWrite service endpoint interfaceMay need to write additional classes representing data structuresWrite class implementing the interfaceCompile classesCreate configuration files and run JWSDP tools to create web serviceDeploy web service to Tomcat

  • JWSDP: ServerService endpoint interfaceMust extend java.rmi.RemoteEvery method must throw java.rmi.RemoteExceptionParameter/return value data types are restrictedNo public static final declarations (global constants)

  • JWSDP: ServerAllowable parameter/return value data typesJava primitives (int, boolean, etc.)Primitive wrapper classes (Integer, etc.)String, Date, Calendar, BigDecimal, BigIntegerjava.xml.namespace.QName, java.net.URIStruct: class consisting entirely of public instance variablesArray of any of the above

  • JWSDP: ServerStruct for currency converter app (data type for return values)

  • JWSDP: ServerService endpoint interface

  • JWSDP: ServerWrite service endpoint interfaceMay need to write additional classes representing data structuresWrite class implementing the interfaceCompile classesCreate configuration files and run JWSDP tools to create web serviceDeploy web service to Tomcat

  • JWSDP: ServerClass CurConImpl contains methods, for example:

  • JWSDP: ServerWrite service endpoint interfaceMay need to write additional classes representing data structuresWrite class implementing the interfaceCompile classesCreate configuration files and run JWSDP tools to create web serviceDeploy web service to Tomcat

  • JWSDP: ServerConfiguration file input to wscompile to create serverNamespacesused inWSDL(normally,unique URLsat yourWeb site)

  • JWSDP: ServerConfiguration file for web service

  • JWSDP: ServerConfiguration file for web serviceLikeservletin web.xmlLikeservlet-mappinginweb.xmlContext path

  • JWSDP: ServerAlso need a minimal web.xml

  • JWSDP: ServerRun jar and wsdeploy to create a Web Archive (WAR) file converter.warName must match urlPatternBase value

  • JWSDP: ServerWrite service endpoint interfaceMay need to write additional classes representing data structuresWrite class implementing the interfaceCompile classesCreate configuration files and run JWSDP tools to create web serviceDeploy web service to Tomcat

  • JWSDP: ServerJust copy converter.war to Tomcat webapps directoryMay need to use Manager app to deployEnter converter.war in WAR or Directory URL text box

  • JWSDP: ServerTesting success:Visit http://localhost:8080/converter/currency

  • JWSDP: ClientGoal: write a JSP-based clientInput: currency and valueOutput: table of equivalent values

  • JWSDP: ClientConfiguration file input to wscompile to create client

  • JWSDP: ClientDirectory structure (wscompile generates content of classes and src)

  • JWSDP: ClientStarting point for writing a client (if the web service author does not explain how):In the WSDL, find the name attribute of the service element

    Look in Java file with this name to see how to obtain a proxy object for the service

    Data type of proxy objectMethod called to obtain object

  • JWSDP: ClientObtaining the proxy object:Java file consisting of service name followed by _Impl defines a class implementing the proxy-generating interfaceClient code begins with method call on this class:

  • JWSDP: ClientUsing the proxy object:

  • JWSDP: ClientStructs will be represented as JavaBeans classes, regardless of how they are defined on the server

  • JWSDP: ClientBean obtaining and calling proxy object:

  • JWSDP: ClientJSP document using the bean:Call to getExValues()Call to getEuros()

  • WSDL Example

    Target namespace: namespace for names (e.g., of operations) defined by the WSDLWSDLnamespacesXML Schema NSNamespacesspecified inconfig files

  • WSDL ExampleDefines structusing XMLSchemaNamespace fordata type definitions(ns2 in rest of document)

  • WSDL ExampleInputmessages(parameterlists)Outputmessages(responsedata types)Data type defined byXML Schema

  • WSDL Example

  • WSDL ExampleImplement the operations using SOAP encoding ofdata structures and RPC (JWSDP defaults)

  • WSDL Example

    Replaced by serverwhen WSDL is visited

  • WSDL ExampleSummary:types uses XML Schema to define data typesmessage elements define parameter lists and return types using types and XML SchemaportType defines abstract API for operations using messagesbinding specifies how messages will be communicated and operations calledservice associates URL with binding

  • XML SchemaHow do we send a Java double value to a web service using XML?Is scientific notation allowed?How large can the value be?Etc.What if we want to send an object?And what if the object contains references to other objects?

  • XML SchemaXML Schema addresses such questionsDefines a number of simple data types, includingRange of allowed valuesHow values are represented as stringsProvides facilities for defining data structures in terms of simple types or other data structuresCan also be used in place of XML DTD

  • XML SchemaBuilt-in data types

    Types corresponding to Java primitive types: boolean, byte,int, double, etc.String representations much as JavaException: can use 0 for false, 1 for trueNo char; use string insteadXML DTD types (ID, CDATA, etc.)Built-in type

  • XML SchemaBuilt-in data typesinteger and decimal (arbitrary precision)dates, times, and related subtypesURLsXML namespace qualified namesbinary datasome restricted forms of the above, e.g., nonNegativeInteger

  • XML SchemaXML Schema namespace defining built-in types is called the document namespace

    Standard prefix for this namespace is xsd

  • XML Schema

    Plus Java primitive types (int, etc.)

  • XML SchemaMapping from XML Schema data types to Java:Primitives: one-for-one mappingdate, time, dateTime: map to Calendarmost others: map to String

  • XML SchemaElements in the document namespace can declare user-defined data types Two XML Schema data types:Complex: requires markup to represent within an XML documentSimple: can be represented as character data

  • XML SchemaUser-defined data types are declared in the types element of a WSDLExample: ExchangeValueIn WSDL, user-defined types can be usedTo define other data types within types elementTo specify data types of parameters and return values in message elements

  • XML Schema

  • XML SchemaAn XML schema is markup that Is written according to the XML Schema vocabularyDefines an XML vocabularyA schema document is an XML document consisting entirely of an XML schemaA document conforming with an XML schema vocabulary is call an instance of the schema

  • XML SchemaRoot element of the markup of an XML schema is schemaDefine data types with elements:complexTypesimpleTypeAn XML schema can also define other vocabulary aspects (allowed elements, element content) that we wont cover

  • XML SchemaOne way to define simple types: restrict an existing simple base typeBase type

  • XML SchemaBuilt-in types all have facets, that is, aspects that can be restrictedenumeration is a facet that applies to all built-in types except booleanlength, minLength, maxLength apply to string-like types (e.g., string, QName, anyURI)minInclusive, maxInclusive, minExclusive, maxExclusive apply to numeric and time-oriented typestotalDigits, fractionDigits apply to numeric types

  • XML SchemaRestricting multiple facets:

  • XML Schemapattern facet applies to most types (except a few DTD)specifies regular expression

  • XML SchemaOther simple typesUnion: combine two or more types

    Lists of values of simple type

  • XML SchemaComplex typeDefined in an XML schema

    Used in an instance document

  • XML SchemaComplex type can be used in placed of XML DTD content specificationsequence element is equivalent to , operator in DTD

  • XML Schema

  • XML SchemaInstance namespace

    Normally associated with prefix xsiUsed within instance documents to define null-valued elements

    define data types

  • SOAP

  • SOAP

  • SOAPAlternate form

  • SOAPSOAP encoding of arrays in WSDL

  • SOAPArray in SOAP document

  • SOAPIf SOAP is sent via HTTP, request must include SOAPAction header fieldEither empty or a URICan be used to pass operation rather than embedding in body of message

  • Web Services TechnologiesOther implementation of JAX-RPC and/or Java-based web servicesApache AxisIBM WebSphereMicrosoft support for web services: .NETPHP also has web services tools

  • Web Services TechnologiesUniversal Discovery, Description, and Integration (UDDI)Technology for creating directories of web servicesWeb Services-Interoperability Organization (WS-I) Basic ProfileSpecification of how web services should be used to enhance interoperabilityMust use XML Schema and literal encoding (rather than SOAP encoding)