Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Web Services Semantic Web - Fall 2005 Computer Engineering Department Sharif University of Technology
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Outline What are web services? Definitions Advantages Challenges Architecture WS Protocol Stack SOAP WSDL UDDI Apache Axis
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Web evolution Program the Web XML Browse the Web HTML T C P/IP Connect the Web Technology Applications TextHypertext Applications FTP, , Gopher Web pages Web services
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Definitions Definition 1: A web service is a service (“program”) that can be invoked from another program via the web. Definition 2: “Web Services are self-contained, self-describing, modular applications that can be published, located, and invoked across the Web”. – IBM Web Services Tutorial Definition 3: A Web Service is a service on the Internet that Use a standardized XML messaging system Not tied to any operating system or programming language Optional features Self-describing: provide public interface to the service via a common XML grammar Discoverable: Interested parties can find a service and locate its interface
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Examples Flight Reservation Weather Service Amazon.com web services Retrieve geographic information Search the web, check spellings One of the first useful Web Services built around SOAP Allows you to integrate your application with Google’s search, spell check, and cached page databases.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall A Basic Web Service Language: Perl Operating System: Windows 2000 Language: Java Operating System: Linux XML
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Web Services Advantages Use open, text-based standards, which enable components written in different languages and for different platforms to communicate. Promote a modular approach to programming, so multiple organizations can communicate with the same Web service. Self-describing (metadata for access and use) Discoverable (search and locate in registries) loosely coupled (i.e. Services should not be dependent on each other).
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Service Oriented Architecture (Basic Model) Service Broker Service User Service Provider Find PublishBind UDDI WSDL SOAP SOAP – Simple Object Access Protocol / SOA Protocol WSDL – Web Services Description Language UDDI – Universal, Description, Discovery, and Integration
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Service Interaction I book planes I book car Rentals I book hotels I locate services I organise holidays Get a car rental quote locate service ask for quote Is quote good enough? Yes Reserve car, provisionally … get other resources reserved Confirm reservation Service Identifier I convert currency I know the weather quote
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Web Service Protocol Stack Discovery UDDI Description WSDL XML Messaging XML-RPC, SOAP,XML Transport HTTP,SMTP,FTP Transporting XML messages between client and server Encoding messages in XML format Describing Web Services interface Searching / Publishing Web Services
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Simple Object Access Protocol (SOAP) SOAP is an XML-based protocol designed to exchange information in a distributed environment (a communication protocol). SOAP is platform & language independent SOAP is a W3C standard
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall SOAP: Message Structure <soap:Envelope xmlns:soap=" soap:encodingStyle=" SOAP Envelope SOAP Header SOAP Body Message Name & Data Headers
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall SOAP: Request Example
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall SOAP: Response Example
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall SOAP Advantages/Disadvantages Advantages Human-readable XML Easy to debug SOAP runs over HTTP Firewalls not affected Services can be written in any language, platform or operating system. Disadvantages S-L-O W XML produces a lot of overhead for small messages
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL Web Services Description Language WSDL is an XML-based format designed to describe the interfaces exposed by a service What a service does? How clients can use it? Separation of abstract service description from concrete messaging format: An abstract section describing the interfaces in a protocol- independent way A concrete section relating the abstract definitions with the specific protocols It can be used with all protocols (HTTP, SMTP, etc.), but it normally runs over HTTP. If sender & receiver share and understand same WSDL file, interoperability is guaranteed.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL: Definitions A WSDL document defines services as a collection of network endpoints or ports, where the port types are abstract collection of operations, and the concrete protocol and data format specifications for a particular port type constitutes a reusable binding. Types: a container for data type definitions using some type system such as XSD. Message: an abstract, typed definition of the data being communicated. Operation: an abstract description of an action supported by the service. Port Type: an abstract set of operations supported by one or more endpoints. They are equivalent to interfaces. Binding: a concrete protocol and data format specification for a particular port type. The interfaces are bound to specific network and transport protocols. It is akin to implementing an interface. Port: a single endpoint defined as a combination of a binding and a network address. Service: a collection of related endpoints.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL Structure
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The The types element contains XML Schemas defining the datatypes that are to be passed to and from the web service
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The The element is used to define the messages that will be exchanged between the client and the service These message elements contain elements, which will be using types defined in the types element All the parts are namespace qualified
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The The types and messages have been defined, but they have not been defined in terms of where they fit in the functionality of the web service This is done within and elements A portType is analogous to a class An operation is analogous to a method in that class
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Types of There are four distinct types of operation Synchronous Request-response - The service receives a message and sends a reply Solicit-response - The service sends a message and receives a reply message Asynchronous One-way - The service receives a message Notification - The service sends a message All of these can be defined in WSDL
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Defining the type of operation Presence and order of input/output elements defines the type of operation. Request-response Solicit-response One-way only Notification only
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The element This element is used to define the mechanism that the client will actually use to interact with the web service The most common choice is currently SOAP The binding element defines the protocol specific information for the portTypes previously defined
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The binding tag The tag indicates that we will map a to a protocol Indicates we will be using the SOAP binding extensions to map the operations. The alternative to “rpc” is “document”. ( to use GET/POST use to use MIME use )
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The final component of a WSDL file is the element The element defines elements that specify where requests should be sent The subelement identifies the URL of the service The precise content of elements will be dependent upon the mechanism, i.e. SOAP, HTTP or MIME
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL: Example (1/5) <definitions name="StockQuote" targetNamespace=" xmlns:tns=" xmlns:xsd=" xmlns:xsda=" xmlns:soap=" xmlns:soapenc=" xmlns=" <schema targetNamespace=" xmlns="
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL: Example (2/5
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL: Example (3/5)
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL: Example (4/5) <soap:body use="encoded" namespace=" encodingStyle="
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall WSDL: Example (5/5) My first service
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall UDDI U niversal D escription, D iscovery and I ntegration A Web Service registry & discovery mechanism for retrieving pointers for web services interfaces Publish your business information and technical details of your Web Service Search for other Web Services and connect to them UDDI is not only limited to XML Web Services The key to the ultimate success of Web services, but has some key limitations, and alternative discovery methods are provided by ebXML and WS-Inspection.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall UDDI Details SOAP is used to talk to UDDI registries White pages Business information (name, contact info) Yellow pages Categorization (industry, products, location) Green pages Technical specifications (service description)
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Addressing Addressing Axis Axis EWS EWS JaxMe JaxMe jUDDI jUDDI jUDDI (pronounced "Judy") is an open source Java implementation of the Universal Description, Discovery, and Integration (UDDI) specification for Web Services. Kandula Kandula Mirae Mirae Muse Muse Pubscribe Pubscribe Sandesha Sandesha Scout Scout SOAP SOAP TSIK TSIK Woden Woden WSIF WSIF The Web Services Invocation Framework (WSIF) is a simple Java API for invoking Web services, no matter how or where the services are provided. WSRF WSRF WSS4J WSS4J XML-RPC XML-RPC
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Apache Axis Apache Axis is an Open Source SOAP server and client It is completely written in Java The server can be executed as a web application into servlet engines such as Jakarta Tomcat
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Standard mappings from WSDL to Java XML Schema DatatypeJava Datatype xsd:base64Binarybyte[] xsd:booleanboolean xsd:bytebyte xsd:dateTimejava.util.Calendar xsd:decimaljava.math.BigDecimal xsd:doubledouble xsd:floatfloat xsd:hexBinarybyte[]
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Standard mappings from WSDL to Java XML Schema DatatypeJava Datatype xsd:intint xsd:integerjava.math.BigInteger xsd:longlong xsd:QNamejavax.xml.namespace.QName xsd:shortshort xsd:stringjava.lang.String
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Publishing Web Services with Axis Let’s say we have a simple Java class like the following: public class Converter { public double toLire(double euro) { return euro * ; } public double toEuro(double lire) { return lire / ; }
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Publishing Web Services with Axis JWS (Java Web Service) files – Instant deploying Step 1 Copy Converter.java file into your axis webapp directory, and rename it as Converter.jws Step 2 You should now be able to access the service at the following URL (assuming your Axis web application is on port 8080):
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Consuming Web Services with Axis import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; public class ConverterClient { public static void main(String args[]) { try { String endpoint = " Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperationName(new QName(" "toLire")); Double ret = (Double)call.invoke(new Object[] {new Double(10.0)}); System.out.println("10 euro = " + ret.doubleValue() + " lire"); } catch (Exception e) { e.printStackTrace(); }
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Consuming Web Services with.NET (1/2) C# Client Create a new C# console application project Add a class called ConverterClient Add a web reference to in the project, otherwise the class ConverterService will not be found.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Consuming Web Services with.NET (2/2) using System; using ConsoleApplication.localhost; namespace ConsoleApplication { /// /// Summary description for Class1. /// class ConverterClient { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { ConverterService converter = new ConverterService(); System.Console.WriteLine("10 euro = {0}", converter.toLire(10)); System.Console.ReadLine(); }
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Using the Axis TCP Monitor (tcpmon) The tcpmon utility keeps a log of all request/response SOAP messages It can be found in the org.apache.axis.utils package To run it from the command line: java org.apache.axis.utils.tcpmon
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Publishing Web Services with.NET (1/2) Visual Studio.NET 2003 From the File menu, point to New, and click New Project Select ASP.NET Web service Change the Location if necessary Click OK Open the code window Add the following code
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Publishing Web Services with.NET (2/2) [WebMethod] public double toLire(double euro) { return euro * ; } [WebMethod] public double toEuro(double lire) { return lire / ; }
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The Java client (1/2) Generate the stub to access to the Web Service java org.apache.axis.wsdl.WSDL2Java This tool generates the following files: Service1.java Service1Locator.java Service1Soap.java ServiceSoapStub.java
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall The Java Client (2/2) import org.tempuri.*; public class DotNetConverterClient { public static void main(String args[]) { try { Service1 service = new Service1Locator(); Service1Soap calculator = service.getService1Soap(); System.out.println("10 euro = " + calculator.toLire(10) + " lire"); } catch (Exception e) { e.printStackTrace(); }
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall Web Services Challenges The standards that drive Web services are still in draft form. Web services need standard security procedures (a common problem to all of the distributed computing solutions). The leading registry, based on the UDDI specification, has some key limitations, and alternative discovery methods are needed. Web services need Quality of Service (QoS) support from Web Services Registries, Brokerages, and Network Providers.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall References Web Services Activity W3C Web Services glossary