190 likes | 307 Views
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
E N D
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 • What is WSDL? • Development plan for Service Requestor • Development plan for Service Provider
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
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
XML Messaging There are two ways of XML Messaging • XML-RPC • SOAP
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
Sample XML-RPC Request <methodCall> <methodName> com.agram.sayHello </methodName> <params> <param> <value>Java</value> </param> </params> </methodCall>
Sample XML-RPC Response <methodResponse> <params> <param> <value> <string>Hello Java</string> </value> </param> </params> </ methodResponse >
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.
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 SOAP Message Envelope Header Body
Sample SOAP Request <SOAP-ENV:Envelope xmlns: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>
Sample SOAP Response <SOAP-ENV:Envelope xmlns: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>
What is WSDL? • Web Services Description Language • Has 6 major elements • definitions – defines the name of the web service • types– describes all the data types that will be transmitted • message – defines the name of the message that will be transmitted • portType – defines the operations • binding – defines how the message will be transmitted • service – defines where the service is located
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 Development plan for Service Requestor
1) Create the core functionality 2) Create XML-RPC or SOAP service wrapper 3) Create service description file 4) Deploy service 5) Register new service via UDDI Development plan for Service Provider
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....
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
Exercise • Make a web service client in Java.Use an appropriate Web Service, ie. a weather serviceF.eks iistest.noea.dk/weather • Make a simple webservice in Java.Use NetBeans, Eclipse or Axis