19
19 - WebServices

19 - WebServices

Embed Size (px)

DESCRIPTION

19 - WebServices. Webservices in Java. Web Service client Selected and edited slides from Siva Jagadeesan The original version is here: Intro to Web Services and Apache Axis. Outline. Web Services Basics What is Web Service? Web Services Architecture XML Messaging XML-RPC SOAP - PowerPoint PPT Presentation

Citation preview

19 - WebServices

2NOEA 2009Java-kursus – Web Services

Webservices in Java

• Web Service client• Selected and edited slides from Siva Jagadeesan• The original version is here:

Intro to Web Services and Apache Axis

3NOEA 2009Java-kursus – Web Services

Outline

• Web Services Basics– What is Web Service?– Web Services Architecture– XML Messaging

• XML-RPC• SOAP

– What is WSDL?– Development plan for Service Requestor– Development plan for Service Provider

4NOEA 2009Java-kursus – Web Services

Outline

• Intro to Apache Axis– What is Apache Axis?– Architecture of Apache Axis– Features of Apache Axis– Installing Apache Axis– Publishing Web Service through Apache Axis– Walkthrough of deploying and accessing a simple web

service using Apache Axis

5NOEA 2009Java-kursus – Web Services

What is Web Service?

A Web Service is any service that – is available over the web– uses standardized XML messaging– is OS and Programming language independent

6NOEA 2009Java-kursus – Web Services

XML Messaging

There are two ways of XML Messaging

• XML-RPC

• SOAP

7NOEA 2009Java-kursus – Web Services

What is XML-RPC ?

• is a simple protocol that uses XML messages to perform RPC

• Request are encoded in XML and send via HTTP• Response are encoded in XML and received via HTTP• is a easiest way to get started with web services

8NOEA 2009Java-kursus – Web Services

Sample XML-RPC Request

<methodCall>

<methodName>

com.agram.sayHello

</methodName>

<params>

<param>

<value>Java</value>

</param>

</params>

</methodCall>

9NOEA 2009Java-kursus – Web Services

Sample XML-RPC Response

<methodResponse> <params>

<param><value>

<string>Hello Java</string></value>

</param> </params></ methodResponse >

10NOEA 2009Java-kursus – Web Services

What is SOAP?

• Simple Object Access Protocol• SOAP is slightly more complicated than the XML-RPC• SOAP extended XML-RPC• It uses XML namespaces and XML Schemas.

11NOEA 2009Java-kursus – Web Services

SOAP Message

• Envelope is like a wrapper for content• Header is a optional element that

could contain control information• Body element includes requests and

responses• Body element will include a Fault

element in the event of an error

SOAP Message

Envelope

Header

Body

12NOEA 2009Java-kursus – Web Services

Sample SOAP Request

<SOAP-ENV:Envelopexmlns:xsd="http://www.w3.org/2001/XMLSchema"

      xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<SOAP-ENV:Body>     <ns1:sayHello xmlns:ns1="http://agram.com/">       <name xsi:type="xsd:string">Java</name></ns1:sayHello>

  </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

13NOEA 2009Java-kursus – Web Services

Sample SOAP Response

<SOAP-ENV:Envelopexmlns:xsd="http://www.w3.org/2001/XMLSchema"

      xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<SOAP-ENV:Body>     <ns1:sayHelloReponse xmlns:ns1="http://agram.com/"> <result xsi:type="xsd:string">Hello

Java</result> </ns1:sayHelloResponse>   </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

14NOEA 2009Java-kursus – Web Services

What is WSDL?

• Web Services Description Language• Has 6 major elements

1. definitions – defines the name of the web service2. types – describes all the data types that will be transmitted3. message – defines the name of the message that will be transmitted4. portType – defines the operations 5. binding – defines how the message will be transmitted6. service – defines where the service is located

15NOEA 2009Java-kursus – Web Services

Development plan for Service Requestor

1) Find the web service (Google, Xmethods.net etc.)

2) Retrieve service description file

3) Create XML-RPC or SOAP client

4) Invoke remote service

16NOEA 2009Java-kursus – Web Services

Development plan for Service Provider

5) Register new service via UDDI

1) Create the core functionality

2) Create XML-RPC or SOAP service wrapper

3) Create service description file

4) Deploy service

17NOEA 2009Java-kursus – Web Services

Make a WebService with NetBeans

• First install NetBeans EE bundle 5.0 or laterCan be downloaded from www.netbeans.org

• To make a WebService in NetBeans is nearly as easy as in VisualStudio....

18NOEA 2009Java-kursus – Web Services

Live Demo

• Da NetBeans laver om for hver ny version er det bedre med en tutorial fra dem, end screendumps på slides.

• Tutorial for 6+ er her:http://netbeans.org/kb/60/websvc/jax-ws.html

19NOEA 2009Java-kursus – Web Services

Exercise

1. Make a web service client in Java.Use an appropriate Web Service, ie. a weather serviceF.eks iistest.noea.dk/weather

2. Make a simple webservice in Java.Use NetBeans, Eclipse or Axis