0% found this document useful (0 votes)
26 views48 pages

CS8651 Notes 005-5 Edubuzz360

AJAX allows for asynchronous partial page updates without reloading the entire page. The XMLHttpRequest object is used to asynchronously exchange data with a server in the background. Callback functions allow performing partial page updates in AJAX applications by executing additional JavaScript code in response to events like loading or receiving a server response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views48 pages

CS8651 Notes 005-5 Edubuzz360

AJAX allows for asynchronous partial page updates without reloading the entire page. The XMLHttpRequest object is used to asynchronously exchange data with a server in the background. Callback functions allow performing partial page updates in AJAX applications by executing additional JavaScript code in response to events like loading or receiving a server response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

www.edubuzz360.

com

CS8651 -UNIT 5-NOTES


CS8651- Internet Programming 2017Reg
UNIT V - INTRODUCTION TO AJAX and WEB SERVICES
JAX: Ajax Client Server Architecture – XML Http Request Object – Call Back Methods;
Web Services: Introduction – Java web services Basics – Creating, Publishing, Testing and
Describing a Web services WSDL) –Consuming a web service, Database Driven web service
from an application – SOAP.
PART-A
No Questions
Describe AJAX Control Extender Toolkit.
What is the ASP.NET AJAX Control Toolkit?
The ASP.NET AJAX Control Toolkit is an open-source project built on top of the
Microsoft ASP.NET AJAX framework. It is a joint effort between Microsoft and the
ASP.NET AJAX community that provides a powerful infrastructure to write reusable,
customizable and extensible ASP.NET AJAX extenders and controls, as well as a rich
array of controls that can be used out of the box to create an interactive Web
experience.
They are designed using concepts that are familiar to ASP.NET Web Forms
1. application developers. Using the Ajax Control Toolkit, you can build Ajax-enabled
ASP.NET Web Forms applications and ASP.NET
MVC Web applications by dragging the controls from the Visual Studio Toolbox
onto a page. The Ajax Control Toolkit is an open-source project that is part of the
CodePlex Foundation

The AJAX Control Toolkit contains more than 30 controls that enable you to easily create rich,
interactive web pages.

Discuss the advantages of AJAX.

Advantages of AJAX
 Reduce the traffic travels between the client and the server.
 Response time is faster so increases performance and speed.
 You can use JSON (JavaScript Object Notation) which is alternative to XML.
2. JSON is key value pair and works like an array.
 You can use Firefox browser with an add-on called as Firebug to debug all Ajax
calls.
 Ready Open source JavaScript libraries available for use – JQuery, Prototype,
Scriptaculous, etc..
 AJAX communicates over HTTP Protocol.

Identify the role of a callback function in performing a partial page update


in an AJAX application.
3.
Partial-page rendering with UpdatePanels

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

One of the most fascinating controls in the ASP.NET AJAX framework is


the UpdatePanel. This new control replaces the need for a page to refresh during
a postback. Only portions of a page, designated by the UpdatePanel, are updated. This
technique is known as partial-page rendering and can be highly effective in
improving the user experience.

6.1.1. Evolution of the UpdatePanel

For years, programming with the XMLHttpRequest object has been the most
commonly used approach for communicating with the server from client-side script.
The complexities involved in coding those types of applications scared away a lot of
developers. To assist, the overall scripting model in ASP.NET 2.0 was significantly
enhanced to introduce the idea of script callbacks—a way for server controls to
communicate with client-side scripts between callbacks. This model was powerful
because it offered access to the state of all the controls on the page during a callback.
Unfortunately, many developers found the model difficult to work with, and
numerous concerns were raised. The lack of support for passing complex types
as parameters to the server (only strings were allowed) made the prototype too rigid
and exposed its limitations. Developers began to look elsewhere for solutions.

In an effort to address these concerns, members of the ASP.NET team began work on
a communication library built on top of the callbacks. The primary objective of the
library was to simplify the use of callbacks and to provide a rich set of APIs for
enabling the exchange of complex and simple types between the server and client.
From this library came a control called the RefreshPanel. The purpose of the
RefreshPanel was to offer a server control that refreshed the contents of a page
without a page refresh. Out of this hard work, the UpdatePanel emerged, with deeper
integration into the page lifecycle and a more transparent footprint on the page.

NOTE

A callback is a piece of code that is passed in as a parameter or argument to other code. The
other piece of code can call the callback code (usually a function) at any time, even
numerous times, in response to some processing.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Differentiate AJAX forms with HTML5 forms.

AJAX is the name of a communication architecture between web pages and


server side.

JQuery is a javascript library that is written for unifying JS method calls


(regarding DOM manipulation, String and Array functions, DOM queries...etc.)
4.
in all browsers.

HTML5 is the rendering specification to be implemented by all browser


providers. For this rendering to work JS Engine should also be updated, so
HTML5 also means a JS engine with new features like drawing on a canvas.

What is XML Http Request object? List its properties.

The XMLHttpRequest Object


With the XMLHttpRequest object you can update parts of a web page, without
reloading the whole page.

The XMLHttpRequest Object

The XMLHttpRequest object is used to exchange data with a server behind the
scenes.

The XMLHttpRequest object is the developers dream, because you can:

 Update a web page without reloading the page


 Request data from a server after the page has loaded
 Receive data from a server after the page has loaded
5.
 Send data to a server in the background

XMLHttpRequest Object Methods

Method Description

abort() Cancels the current request

getAllResponseHeaders() Returns header information

getResponseHeader() Returns specific header information

open(method,url,async,uname,pswd) Specifies the type of request, the URL,


if the request should be handled
asynchronously or not, and other
optional attributes of a request

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

method: the type of request: GET or


POST
url: the location of the file on the
server
async: true (asynchronous) or false
(synchronous)

send(string) send(string) Sends the request off to


the server.

string: Only used for POST requests

setRequestHeader() Adds a label/value pair to the header


to be sent

XMLHttpRequest Object Properties

Property Description

onreadystatechange Stores a function (or the name of a function) to be


called automatically each time the readyState
property changes

readyState Holds the status of the XMLHttpRequest. Changes


from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready

responseText Returns the response data as a string

responseXML Returns the response data as XML data

status Returns the status-number (e.g. "404" for "Not


Found" or "200" for "OK")

statusText Returns the status-text (e.g. "Not Found" or "OK")

Summarize the need of SOAP and show its structure.

XML Soap
6.
 SOAP stands for Simple Object Access Protocol
 SOAP is an application communication protocol
 SOAP is a format for sending and receiving messages
 SOAP is platform independent

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 SOAP is based on XML


 SOAP is a W3C recommendation

Why SOAP?

It is important for web applications to be able to communicate over the Internet.

The best way to communicate between applications is over HTTP, because HTTP is
supported by all Internet browsers and servers. SOAP was created to accomplish this.

A SOAP message is an ordinary XML document containing the following elements:

 An Envelope element that identifies the XML document as a SOAP message


 A Header element that contains header information
 A Body element that contains call and response information
 A Fault element containing errors and status information

Can you develop the service end point interface in RPC?


Example

Sample Java Beans service endpoint implementation and interface

The following example illustrates a simple explicit Java Beans service


endpoint implementation and the associated service endpoint interface.
/** This is an excerpt from the service implementation file,
EchoServicePortTypeImpl.java package com.ibm.was.wssample.echo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
7.
@javax.jws.WebService(serviceName = "EchoService",
endpointInterface =
"com.ibm.was.wssample.echo.EchoServicePortType",

targetNamespace="http://com/ibm/was/wssample/echo/",
portName="EchoServicePort")
public class EchoServicePortTypeImpl implements EchoServicePortType {

public EchoServicePortTypeImpl() {
}

public String invoke(String obj) {


String str;
....
str = obj;
....

return str;

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

}
/** This is a sample EchoServicePortType.java service interface */
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.*;

@WebService(name = "EchoServicePortType",
targetNamespace =
"http://com/ibm/was/wssample/echo/",
wsdlLocation="WEB-INF/wsdl/Echo.wsdl")
public interface EchoServicePortType {

/** ...the method process ...*/


@WebMethod
@WebResult(name = "response", targetNamespace =
"http://com/ibm/was/wssample/echo/")
@RequestWrapper(localName = "invoke", targetNamespace =
"http://com/ibm/was/wssample/echo/", className =
"com.ibm.was.wssample.echo.Invoke")
@ResponseWrapper(localName = "echoStringResponse",
targetNamespace = "http://com/ibm/was/wssample/echo/", className =
"com.ibm.was.wssample.echo.EchoStringResponse")
public String invoke(
@WebParam(name = "arg0", targetNamespace =
"http://com/ibm/was/wssample/echo/")
String arg0);

Sample Provider endpoint implementation

The following example illustrates a simple Provider service endpoint


interface for a Java class.
package jaxws.provider.source;
import javax.xml.ws.Provider;
import javax.xml.ws.WebServiceProvider;
import javax.xml.transform.Source;

@WebServiceProvider() public class SourceProvider implements


Provider<Source> {

public Source invoke(Source data) {


return data;
}
}

List any four examples of web services.


8.
A Web Service Example

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

In the following example we will use ASP.NET to create a simple Web


Service that converts the temperature from Fahrenheit to Celsius, and
vice versa:

<%@ WebService Language="VBScript" Class="TempConvert" %>

Imports System
Imports System.Web.Services

Public Class TempConvert :Inherits WebService

<WebMethod()> Public Function FahrenheitToCelsius(ByVal


Fahrenheit As String) As String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function

<WebMethod()> Public Function CelsiusToFahrenheit(ByVal Celsius


As String) As String
dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end function

end class

This document is saved as an .asmx file. This is the ASP.NET file


extension for XML Web Services.

Put the Web Service on Your Web Site

Using a form and the HTTP POST method, you can put the web service
on your site, like this:

Fahrenheit to Celsius: Submit

Celsius to Fahrenheit: Submit

code to add the Web Service to a web page:

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

<form action='tempconvert.asmx/FahrenheitToCelsius'
method="post" target="_blank">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td>
<input class="frmInput" type="text" size="30" name="Fahrenhei
t">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="submit" value="Submit" class="button">
</td>
</tr>
</table>
</form>

<form action='tempconvert.asmx/CelsiusToFahrenheit'
method="post" target="_blank">
<table>
<tr>
<td>Celsius to Fahrenheit:</td>
<td>
<input class="frmInput" type="text" size="30" name="Celsius">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input type="submit" value="Submit" class="button">
</td>
</tr>
</table>
</form>

Substitute the "tempconvert.asmx" with the address of your web


service like:

http://www.example.com/xml/tempconvert.asmx

Discover an example for web service registry along with its functions.
Web Services Discovery provides access to software systems over the Internet using
standard protocols. In the most basic scenario there is a Web Service Provider that
9. publishes a service and a Web Service Consumer that uses this service. Web Service
Discovery is the process of finding suitable web services for a given task.[1]
Publishing a web service involves creating a software artifact and making it
accessible to potential consumers. Web service providers augment a service endpoint

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

interface with an interface description using the Web Services Description


Language (WSDL) so that a consumer can use the service.
Universal Description, Discovery, and Integration (UDDI) is an XML-based
registry for business internet services. A provider can explicitly register a service with
a Web Services Registry such as UDDI or publish additional documents intended to
facilitate discovery such as Web Services Inspection Language (WSIL) documents.
The service users or consumers can search web services manually or automatically.
The implementation of UDDI servers and WSIL engines should provide simple
search APIs or web-based GUI to help find Web services.
Web services may also be discovered using multicast mechanisms like WS-
Discovery, thus reducing the need for centralized registries in smaller networks.

Analyze the need for web service.

We should use web services as it comes with various advantages listed below

Re-usability

Once we develop some business logic,we can make it reuse for other applications
Example:
If 10 different applications requires to use our logic
We can expose our logic over a network as a web service
So all the 10 different application can access it from the network.

Interoperability

It provides the freedom for a developers to choose whatever the technology they
want to use for development.
10.
Web services uses a set of standards and protocols and enable us to achieve
interoperability.
Hence applications developed in Java,Mainframe,Ruby or any other technology can
call the web service and use it.

Loosely coupled

Web service exist independent of the other parts of the application that uses it.
So any changes to the application can be made without affecting the web service.

Deployability

It is very easy to deploy the web application as they are deployed over standard
internet technologies.

Give the uses of WSDL along with its definition.


11.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

WSDL stands for Web Services Description Language. It is the standard


format for describing a web service. WSDL was developed jointly by Microsoft
and IBM.

Features of WSDL
 WSDL is an XML-based protocol for information exchange in decentralized and
distributed environments.
 WSDL definitions describe how to access a web service and what operations it
will perform.
 WSDL is a language for describing how to interface with XML-based services.
 WSDL is an integral part of Universal Description, Discovery, and Integration
(UDDI), an XML-based worldwide business registry.
 WSDL is the language that UDDI uses.
 WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.

WSDL Usage
WSDL is often used in combination with SOAP and XML Schema to provide
web services over the Internet. A client program connecting to a web service
can read the WSDL to determine what functions are available on the server.
Any special datatypes used are embedded in the WSDL file in the form of XML
Schema. The client can then use SOAP to actually call one of the functions
listed in the WSDL.

Compare SOAP and HTTP.

Difference between SOAP and HTTP


SOAP HTTP
 SOAP was originally defined as  The HTTP or Hypertext
S- Simple O- Object A-Access Transfer Protocol (HTTP)
P-protocol. is an application protocol
 It is a protocol specification which is used for
which is used for exchanging distributed, collaborative
structured information. and hypermedia
12.
 It is used in the implementation information systems.
of web services in computer-  HTTP is widely regarded
based networks. as the foundation of data
 SOAP for its message communication for the
format relies on XML World Wide Web (WWW).
Information set and sometimes  Hypertext is a structured
relies on other application text that uses logical links
layer protocols as well, such or hyperlinks between
as Hypertext Transfer those nodes that containing
text. HTTP is the protocol
Protocol (HTTP) or Simple

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Mail Transfer Protocol for exchanging or


(SMTP). transferring hypertext.
 It is used for message  The standards
development
negotiation and transmission
of HTTP when it was
mainly. innovated was coordinated
 SOAP forms the foundation by the Internet Engineering
layer of a web services Task Force and the World
protocol stack. Wide Web Consortium also
called as W3C.

Summarize the need for enhancing security in web services.

Definition - What does Web Services Security (WS Security) mean?


Web Services Security (WS Security) is a specification that defines how
security measures are implemented in web services to protect them from
external attacks. It is a set of protocols that ensure security for SOAP-based
messages by implementing the principles of confidentiality, integrity and
authentication.
Because Web services are independent of any hardware and software
13. implementations, WS-Security protocols need to be flexible enough to
accommodate new security mechanisms and provide alternative mechanisms
if an approach is not suitable. Because SOAP-based messages traverse
multiple intermediaries, security protocols need to be able to identify fake
nodes and prevent data interpretation at any nodes. WS-Security combines
the best approaches to tackle different security problems by allowing the
developer to customize a particular security solution for a part of the problem.
For example, the developer can select digital signatures for non-repudiation
and Kerberos for authentication.

Name the types of indicators along with the definition.

Web Services Security (WSS)


Web Services Security (WSS or WS-Security) describes enhancements
14. to SOAP messaging in order to provide quality of protection through message
integrity, and single message authentication. These mechanisms can be used to
accommodate a wide variety of security models and encryption technologies.

The scope of the Web Services Security Technical Committee is the support of
security mechanisms in the following areas:

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 Using XML Signature to provide SOAP message integrity for Web Services
 Using XML Encryption to provide SOAP message confidentiality for Web Services
 Attaching and/or referencing security tokens in headers of SOAP messages. Options include:
 Username token
 SAML
 XrML
 Kerberos
 X.509
 Carrying security information for potentially multiple, designated actors
 Associating signatures with security tokens
 Each of the security mechanisms will use implementation and language neutral XML formats
defined in XML Schema.

Classify the basic concepts behind JAX-RPC technology.


JAX-RPC
Java APIs for XML-based Remote Procedure Call ( JAX-RPC) help with Web
service interoperability and accessibility by defining Java APIs that Java applications
use to develop and access Web services. JAX-RPC fully embraces the heterogeneous
nature of Web services -- it allows a JAX-RPC client to talk to another Web service
deployed on a different platform and coded in a different language. Similarly, it also
allows clients on other platforms and coded in different languages to talk to a JAX-
RPC service. JAX-RPC also defines the mapping between WSDL service
descriptions and Java interfaces.

15. Th the JAX-RPC technology and describes its client and server programming
models. JAX-RPC hides the complexity of underlying protocols and message-level
processing from application developers crafting Web services using the Java 2
platform. The API combines XML with Remote Procedure Call (RPC), which is a
mechanism enabling clients to execute procedures on distributed or remote systems,
so that developers can build Web services and clients. The JAX-RPC remote
procedure calls are represented by an XML infoset and they are carried over a
network transport. While the JAX-RPC APIs rely on a XML-based protocol and a
network transport, the APIs themselves are independent of a specific protocol or
transport. The current JAX-RPC implementation relies on the SOAP 1.1 protocol and
HTTP 1.1 network transport.

What are the benefits of UDDI?


Problems the UDDI specification can help to solve:
Making it possible to discover the right business from the millions currently online
16. Defining how to enable commerce once the preferred business is discovered
Reaching new customers and increasing access to current customers
Expanding offerings and extending market reach

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Solving customer-driven need to remove barriers to allow for rapid participation in the
global Internet
economy
Describing services and business processes programmatically in a single, open, and
secure environment

What are the core elements of UDDI?


UDDI defines four core data elements within the data model:
businessEntity (modeling business information)
businessService (describing a service)
tModel (describing specifications, classifications, or identifications)
17. binding Template (mapping between a businessService and the set of tModels that
describe its technical
fingerprint)

Rewrite the definition for UDDI.

UDDI is an XML-based standard for describing, publishing, and finding web


services.
 UDDI stands for Universal Description, Discovery, and Integration.
 UDDI is a specification for a distributed registry of web services.
 UDDI is a platform-independent, open framework.
 UDDI can communicate via SOAP, CORBA, Java RMI Protocol.
 UDDI uses Web Service Definition Language(WSDL) to describe interfaces to
web services.
18.
 UDDI is seen with SOAP and WSDL as one of the three foundation standards of
web services.
 UDDI is an open industry initiative, enabling businesses to discover each other
and define how they interact over the Internet.
UDDI has two sections −
 A registry of all web service's metadata, including a pointer to the WSDL
description of a service.
 A set of WSDL port type definitions for manipulating and searching that registry.

Give the usage of UDDI in web service.

UDDI is an XML-based standard for describing, publishing, and finding web


services.
19.
 UDDI stands for Universal Description, Discovery, and Integration.
 UDDI is a specification for a distributed registry of web services.
 UDDI is a platform-independent, open framework.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 UDDI can communicate via SOAP, CORBA, Java RMI Protocol.


 UDDI uses Web Service Definition Language(WSDL) to describe interfaces to
web services.
 UDDI is seen with SOAP and WSDL as one of the three foundation standards of
web services.
 UDDI is an open industry initiative, enabling businesses to discover each other
and define how they interact over the Internet.
UDDI has two sections −
 A registry of all web service's metadata, including a pointer to the WSDL
description of a service.
 A set of WSDL port type definitions for manipulating and searching that registry.

Define WSDL.
WSDL stands for Web Services Description Language. It is the standard
format for describing a web service. WSDL was developed jointly by Microsoft
and IBM.

Features of WSDL
 WSDL is an XML-based protocol for information exchange in decentralized and
distributed environments.
 WSDL definitions describe how to access a web service and what operations it
will perform.
 WSDL is a language for describing how to interface with XML-based services.
 WSDL is an integral part of Universal Description, Discovery, and Integration
20.
(UDDI), an XML-based worldwide business registry.
 WSDL is the language that UDDI uses.
 WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.

WSDL Usage
WSDL is often used in combination with SOAP and XML Schema to provide
web services over the Internet. A client program connecting to a web service
can read the WSDL to determine what functions are available on the server.
Any special datatypes used are embedded in the WSDL file in the form of XML
Schema. The client can then use SOAP to actually call one of the functions
listed in the WSDL.

PART-B
(i) Describe in detail about the AJAX architecture.
1.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

(ii) List out the call back methods.

(i) Analyze various concepts of RPC.

Remote Procedure Call (RPC)


A remote procedure call is an interprocess communication technique that is
used for client-server based applications. It is also known as a subroutine call
or a function call.
A client has a request message that the RPC translates and sends to the
server. This request may be a procedure or a function call to a remote server.
When the server receives the request, it sends the required response back to
the client. The client is blocked while the server is processing the call and only
resumed execution after the server is finished.
The sequence of events in a remote procedure call are given as follows:

 The client stub is called by the client.


 The client stub makes a system call to send the message to the server and puts
the parameters in the message.
 The message is sent from the client to the server by the client’s operating
system.
 The message is passed to the server stub by the server operating system.
 The parameters are removed from the message by the server stub.
 Then, the server procedure is called by the server stub.
2.
A diagram that demonstrates this is as follows:

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Advantages of Remote Procedure Call


Some of the advantages of RPC are as follows:

 Remote procedure calls support process oriented and thread oriented models.
 The internal message passing mechanism of RPC is hidden from the user.
 The effort to re-write and re-develop the code is minimum in remote procedure
calls.
 Remote procedure calls can be used in distributed environment as well as the
local environment.
 Many of the protocol layers are omitted by RPC to improve performance.

Disadvantages of Remote Procedure Call


Some of the disadvantages of RPC are as follows:

 The remote procedure call is a concept that can be implemented in different


ways. It is not a standard.
 There is no flexibility in RPC for hardware architecture. It is only interaction
based.
 There is an increase in costs because of remote procedure call.

(ii) Explain the basic concepts behind JAX-RPC.

JAX-RPC stands for Java API for XML-based RPC. It's an API for building
Web services and clients that used remote procedure calls (RPC) and XML.
Often used in a distributed client/server model, an RPC mechanism enables
clients to execute procedures on other systems.

In JAX-RPC, a remote procedure call is represented by an XML-based


protocol such as SOAP. The SOAP specification defines envelope structure,
encoding rules, and a convention for representing remote procedure calls
and responses. These calls and responses are transmitted as SOAP messages
over HTTP. In this release, JAX-RPC relies on SOAP 1.1 and HTTP 1.1.

Although JAX-RPC relies on complex protocols, the API hides this


complexity from the application developer. On the server side, the
developer specifies the remote procedures by defining methods in an
interface written in the Java programming language. The developer also
codes one or more classes that implement those methods. Client programs
are also easy to code. A client creates a proxy, a local object representing
the service, and then simply invokes methods on the proxy.

With JAX-RPC, clients and Web services have a big advantage--the


platform independence of the Java programming language. In addition,
JAX-RPC is not restrictive: a JAX-RPC client can access a Web service that
is not running on the Java platform and vice versa. This flexibility is
possible because JAX-RPC uses technologies defined by the World Wide

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Web Consortium (W3C): HTTP, SOAP, and the Web Service Description
Language (WSDL). WSDL specifies an XML format for describing a
service as a set of endpoints operating on messages.

Explain in detail with an example of Java Web Services.


With a simple example illustrate the steps to create a java web service. (NOV/DEC
2012)
Writing a java web service
Currency conversion Service
Writing a server for a service using JWSDP 1.3 tools
Application: currency converter
Three operations:
fromDollars
fromEuros
fromYen
Input: value in specified currency
Output: object containing input value and equivalent values in other two
currencies
Writing server software
1. Write service endpoint interface
• May need to write additional classes representing data structures
2. Write class implementing the interface
3. Compile classes
4. Create configuration files and run JWSDP tools to create web service
5. Deploy web service to Tomcat
service endpoint interface
3. The Web service endpoint interface is used to define the ‘Web services
methods’.
A Web service endpoint interface must conform to the rules of a JAX-RPC
service definition
interface.
a service endpoint interface (SEI) that defines the interface of the web service.
Configuration files are XML files that can be changed as needed. Developers
can use
configuration files to change settings without recompiling applications.
Administrators can use
configuration files to set policies that affect how applications run on their
computers.
config.xml : Defines the URL for WSDL file location. Each Web services has
a corresponding
WSDL (Web service Definition Language) document.
JWSDP: Server

Rules for Service endpoint interface


Must extend java.rmi.Remote
declares a set of methods that may be invoked from a remote Java Virtual
Machine(JVM)
Every method must throw java.rmi.RemoteException

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Parameter/return value data types are restricted


No public static final declarations (global constants) It must not have constant
declarations
Allowable parameter/return value data types
Java primitives (int, boolean, etc.)
Primitive wrapper classes (Integer, etc.)
String, Date, Calendar, BigDecimal, BigInteger
java.xml.namespace.QName, java.net.URI
Struct: class consisting entirely of public instance variables
Array of any of the above
Struct for currency converter app (data type for return values)

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Run jar and wsdeploy to create a Web Archive (WAR) file converter.war
Name must match urlPatternBase value

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

jaxrpc-ri.xml: Defines the various end points for referencing a Web service.
wscompile: The wscompile tool generates stubs, and WSDL files used in JAX-
RPC clients and
services. The tool reads as input a configuration file and either a WSDL file or an
RMI interface
that defines the service.
wsdeploy: Reads a WAR file (something like Jar file) and the jaxrpc-ri.xml file
and then
generates another WAR file that is ready for deployment
Write service endpoint interface
May need to write additional classes representing data structures
Write class implementing the interface
Compile classes
Create configuration files and run JWSDP tools to create web service
Deploy web service to Tomcat
Just copy converter.war to Tomcat webapps directory
May need to use Manager app to deploy
Enter converter.war in “WAR or Directory URL” text box
Testing success:
Visit http://localhost:8080/converter/currency

Discuss in detail the architecture of web services.

Architecture of Web Services


4. The Web Services architecture describes how to instantiate the elements and
implement the operations in an interoperable manner.

The architecture of web service interacts among three roles: service provider,
service requester, and service registry. The interaction involves the three
operations: publish, find, and bind. These operations and roles act upon

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

the web services artifacts. The web service artifacts are the web service
software module and its description.

The service provider hosts a network-associable module (web service). It defines


a service description for the web service and publishes it to a service requestor or
service registry. These service requestor uses a find operation to retrieve the
service description locally or from the service registry. It uses the service
description to bind with the service provider and invoke with the web service
implementation.

The following figure illustrates the operations, roles, and their interaction.

Roles in a Web Service Architecture


There are three roles in web service architecture:

o Service Provider
o Service Requestor
o Service Registry

Service Provider

From an architectural perspective, it is the platform that hosts the services.

Service Requestor

Service requestor is the application that is looking for and invoking or initiating
an interaction with a service. The browser plays the requester role, driven by a
consumer or a program without a user interface.

Service Registry

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Service requestors find service and obtain binding information for services during
development.

Operations in a Web Service Architecture


Three behaviors that take place in the microservices:

o Publication of service descriptions (Publish)


o Finding of services descriptions (Find)
o Invoking of service based on service descriptions (Bind)

Publish: In the publish operation, a service description must be published so


that a service requester can find the service.

Find: In the find operation, the service requestor retrieves the service description
directly. It can be involved in two different lifecycle phases for the service
requestor:

o At design, time to retrieve the service's interface description for program


development.
o And, at the runtime to retrieve the service's binding and location
description for invocation.

Bind: In the bind operation, the service requestor invokes or initiates an


interaction with the service at runtime using the binding details in the service
description to locate, contact, and invoke the service.

Artifacts of the web service


There are two artifacts of web services:

o Service
o Service Registry

Service: A service is an interface described by a service description. The service


description is the implementation of the service. A service is a software module
deployed on network-accessible platforms provided by the service provider. It
interacts with a service requestor. Sometimes it also functions as a requestor,
using other Web Services in its implementation.

Service Description: The service description comprises the details of


the interface and implementation of the service. It includes its data types,
operations, binding information, and network location. It can also
categorize other metadata to enable discovery and utilize by service requestors.
It can be published to a service requestor or a service registry.

5. (i) Deduce any two elements of WSDL.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

WSDL (Web services description language)

A web service cannot be used if it cannot be found. The


client invoking the web service should know where the web
service actually resides.

Secondly, the client application needs to know what the web


service actually does, so that it can invoke the right web
service. This is done with the help of the WSDL, known as the
Web services description language. The WSDL file is again an
XML-based file which basically tells the client application what
the web service does. By using the WSDL document, the client
application would be able to understand where the web service
is located and how it can be utilized.

Web Service Example


An example of a WSDL file is given below.

<definitions>
<message name="TutorialRequest">
<part name="TutorialID" type="xsd:string"/>
</message>

<message name="TutorialResponse">
<part name="TutorialName" type="xsd:string"/>
</message>

<portType name="Tutorial_PortType">
<operation name="Tutorial">
<input message="tns:TutorialRequest"/>
<output message="tns:TutorialResponse"/>
</operation>
</portType>

<binding name="Tutorial_Binding" type="tns:Tutorial_PortType">


<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Tutorial">
<soap:operation soapAction="Tutorial"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encodi
ng/"
namespace="urn:examples:Tutorialservice"

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

use="encoded"/>
</input>

<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encodi
ng/"
namespace="urn:examples:Tutorialservice"
use="encoded"/>
</output>
</operation>
</binding>
</definitions>

(ii) Explain the steps for writing web service.

Describe briefly about the elements of WSDL.

he important aspects to note about the above WSDL


declaration are as follows;

1. <message> - The message parameter in the WSDL


definition is used to define the different data elements for
each operation performed by the web service. So in the
example above, we have 2 messages which can be
exchanged between the web service and the client
application, one is the "TutorialRequest", and the other is
the "TutorialResponse" operation. The TutorialRequest
6. contains an element called "TutorialID" which is of the
type string. Similarly, the TutorialResponse operation
contains an element called "TutorialName" which is also
a type string.
2. <portType> - This actually describes the operation
which can be performed by the web service, which in our
case is called Tutorial. This operation can take 2
messages; one is an input message, and the other is the
output message.
3. <binding> - This element contains the protocol which is
used. So in our case, we are defining it to use http
(http://schemas.xmlsoap.org/soap/http). We also
specify other details for the body of the operation, like the

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

namespace and whether the message should be


encoded.

(i) Summarize on the structure of SOAP.

SOAP (Simple Object Access Protocol)

SOAP is known as a transport-independent messaging


protocol. SOAP is based on transferring XML data as SOAP
Messages. Each message has something which is known as
an XML document. Only the structure of the XML document
follows a specific pattern, but not the content. The best part of
Web services and SOAP is that its all sent via HTTP, which is
the standard web protocol.

Here is what a SOAP message consists of


7.
o Each SOAP document needs to have a root element
known as the <Envelope> element. The root element is
the first element in an XML document.
o The "envelope" is in turn divided into 2 parts. The first is
the header, and the next is the body.
o The header contains the routing data which is basically
the information which tells the XML document to which
client it needs to be sent to.
o The body will contain the actual message.

The diagram below shows a simple example of the


communication via SOAP.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

(ii) Describe briefly about SOAP & HTTP.

(i) Demonstrate the building blocks of SOAP.

XML Soap
 SOAP stands for Simple Object Access Protocol
 SOAP is an application communication protocol
 SOAP is a format for sending and receiving messages
 SOAP is platform independent
 SOAP is based on XML
 SOAP is a W3C recommendation

8.
Why SOAP?
It is important for web applications to be able to communicate over the
Internet.

The best way to communicate between applications is over HTTP,


because HTTP is supported by all Internet browsers and servers. SOAP
was created to accomplish this.

SOAP provides a way to communicate between applications running on


different operating systems, with different technologies and
programming languages.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

SOAP Building Blocks


A SOAP message is an ordinary XML document containing the following
elements:

 An Envelope element that identifies the XML document as a


SOAP message
 A Header element that contains header information
 A Body element that contains call and response information
 A Fault element containing errors and status information

Syntax Rules
Here are some important syntax rules:

 A SOAP message MUST be encoded using XML


 A SOAP message MUST use the SOAP Envelope namespace
 A SOAP message must NOT contain a DTD reference
 A SOAP message must NOT contain XML Processing Instructions

(ii) Classify the encoding of struct data and array.

SOAP - Encoding
SOAP includes a built-in set of rules for encoding data types. It enables the
SOAP message to indicate specific data types, such as integers, floats,
doubles, or arrays.
 SOAP data types are divided into two broad categories − scalar types and
compound types.
 Scalar types contain exactly one value such as a last name, price, or product
description.
 Compound types contain multiple values such as a purchase order or a list of
stock quotes.
 Compound types are further subdivided into arrays and structs.

Compound Types
SOAP arrays have a very specific set of rules, which require that you specify
both the element type and array size. SOAP also supports multidimensional
arrays, but not all SOAP implementations support multidimensional
functionality.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

To create an array, you must specify it as an xsi:type of array. The array must
also include an arrayType attribute. This attribute is required to specify the
data type for the contained elements and the dimension(s) of the array.
For example, the following attribute specifies an array of 10 double values −
arrayType = "xsd:double[10]"
In contrast, the following attribute specifies a two-dimensional array of strings

arrayType = "xsd:string[5,5]"
Here is a sample SOAP response with an array of double values −
<?xml version = '1.0' encoding = 'UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-
envelope"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema">

<SOAP-ENV:Body>
<ns1:getPriceListResponse
xmlns:ns1 = "urn:examples:pricelistservice"
SOAP-ENV:encodingStyle =
"http://www.w3.org/2001/12/soap-encoding">

<return xmlns:ns2 =
"http://www.w3.org/2001/09/soap-encoding"
xsi:type = "ns2:Array" ns2:arrayType =
"xsd:double[2]">
<item xsi:type = "xsd:double">54.99</item>
<item xsi:type = "xsd:double">19.99</item>
</return>
</ns1:getPriceListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Structs contain multiple values, but each element is specified with a unique
accessor element. For example, consider an item within a product catalog. In
this case, the struct might contain a product SKU, product name, description,
and price. Here is how such a struct would be represented in a SOAP message

<?xml version = '1.0' encoding = 'UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-
envelope"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema">

<SOAP-ENV:Body>
<ns1:getProductResponse
xmlns:ns1 = "urn:examples:productservice"

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

SOAP-ENV:encodingStyle =
"http://www.w3.org/2001/12/soap-encoding">

<return xmlns:ns2 = "urn:examples" xsi:type =


"ns2:product">
<name xsi:type = "xsd:string">Red Hat
Linux</name>
<price xsi:type = "xsd:double">54.99</price>
<description xsi:type = "xsd:string">
Red Hat Linux Operating System
</description>
<SKU xsi:type = "xsd:string">A358185</SKU>
</return>
</ns1:getProductResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Analyze the various steps in database driven web service with some
example.

Overview of Database Web Services


Web services enable application-to-application interaction over the Web, regardless of platform,
language, or data formats. The key ingredients, including Extensible Markup Language (XML),
Simple Object Access Protocol (SOAP), Web Services Description Language (WSDL), and
Universal Description, Discovery, and Integration (UDDI), have been adopted across the entire
software industry. Web services usually refer to services implemented and deployed in middle-tier
application servers. However, in heterogeneous and disconnected environments, there is an
increasing need to access stored procedures, as well as data and metadata, through Web services
interfaces.

The Database Web services technology is a database approach to Web services. It works in the
following two directions:
9.
 Accessing database resources as a Web service
 Consuming external Web services from the database

Oracle Database can access Web services through PL/SQL packages and Java classes deployed
within the database. Turning Oracle Database into a Web service provider leverages investment in
Java stored procedures, PL/SQL packages, predefined SQL queries, and data manipulation
language (DML). Conversely, consuming external Web services from the database, together with
integration with the SQL engine, enables Enterprise Information Integration.

Using Oracle Database as Web Services


Provider
Web Services use industry-standard mechanisms to provide easy access to remote content and
applications, regardless of the platform and location of the provider and implementation and data
format. Client applications can query and retrieve data from Oracle Database and call stored
procedures using standard Web service protocols. There is no dependency on Oracle-specific

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

database connectivity protocols. This approach is highly beneficial in heterogeneous, distributed,


and disconnected environments.

You can call into the database from a Web service, using the database as a service provider. This
enables you to leverage existing or new SQL, PL/SQL, Java stored procedures, or Java classes
within Oracle Database. You can access and manipulate database tables from a Web service
client.

Illustrate on web services for writing web service client along with
the description of WSDL.

Creating a Web Service Client


Creating a web service client application always starts with an existing WSDL file.

Typically, you retrieve the WSDL directly from a web service provider using the wsimport tool.
The wsimport tool then generates the corresponding Java source code for the interface described by
the WSDL. The Java compiler, javac, is then called to compile the source into class files. The
programming code uses the generated classes to access the web service.

Creating a Client from WSDL


To create a client from WSDL, you must create the following files:

 Client Java File (fromwsdl)


 Client Configuration File (fromwsdl)
 build.xml
 build.properties

Client Java File (fromwsdl)


10.
The client Java file defines the functionality of the web service client. The following code shows
the AddNumbersClient.java file that is provided in the sample.

package fromjava.client;

import com.sun.xml.ws.Closeable;
import java.rmi.RemoteException;

public class AddNumbersClient {


public static void main (String[] args) {
AddNumbersImpl port = null;
try {
port = new
AddNumbersImplService().getAddNumbersImplPort();
int number1 = 10;
int number2 = 20;
System.out.printf ("Invoking addNumbers(%d, %d)\n",
number1, number2);
int result = port.addNumbers (number1, number2);
System.out.printf (
"The result of adding %d and %d is %d.\n\n",
number1, number2, result);

number1 = -10;

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

System.out.printf ("Invoking addNumbers(%d, %d)\n",


number1, number2);
result = port.addNumbers (number1, number2);
System.out.printf (
"The result of adding %d and %d is %d.\n",
number1, number2, result);
} catch (AddNumbersException_Exception ex) {
System.out.printf (
"Caught AddNumbersException_Exception: %s\n",
ex.getFaultInfo ().getDetail ());
} finally {
((Closeable)port).close();
}
}
}

This file specifies two positive integers that are to be added by the web service, passes the integers to
the web service and gets the results from the web service via the port.addNumbers method, and
prints the results to the screen. It then specifies a negative number to be added, gets the results (which
should be an exception), and prints the results (the exception) to the screen.

Client Configuration File (fromwsdl)

This is a sample custom-client.xml file. The wsdlLocation, package name,


and jaxb:package name xml tags are unique to each client and are highlighted in bold text

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="http://localhost:8080/wsit-enabled-fromwsdl/
addnumbers?wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<bindings node="ns1:definitions"
xmlns:ns1="http://schemas.xmlsoap.org/wsdl/">
<package name="fromwsdl.client"/>
</bindings>
<bindings node="ns1:definitions/ns1:types/xsd:schema
[@targetNamespace='http://duke.org']"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://schemas.xmlsoap.org/wsdl/">
<jaxb:schemaBindings>
<jaxb:package name="fromwsdl.client"/>
</jaxb:schemaBindings>
</bindings>
</bindings>

(i) List out the installation steps of JWSDP.


JWSDP
1. Install JDK 6.0 (i.e., JDK 1.6.0)

11. Set up the following environment variables:


JAVA_HOME C:\Program Files\Java\jdk1.6.0_07

Add the following path:


C:\Program Files\Java\jdk1.6.0_07\bin

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

2. Install JWSDP 2.0 & Tomcat 5.0 for JWSDP (based upon Tomcat 5.0.19
that implements
the Java Server Pages 2.0 and Java Servlet 2.4 specifications)

Set up the following environment variables:


JWSDP_HOME C:\Sun\jwsdp-2.0
ANT_HOME C:\Sun\jwsdp-2.0\apache-ant

Add the following path:


C:\Sun\jwsdp-2.0\jwsdp-shared\bin;C:\Sun\jwsdp-2.0\apache-ant\bin

3. Copy examples.zip into C:\ and extract here

4. Copy lib.zip into C:\Sun\jwsdp-2.0\server directory and extract


here
Delete the file "lib.zip"

5. Replace saaj-impl.jar file at the following directories by saaj-


impl-1.3.jar.
Rename it to saaj-impl.jar.

C:\Sun\jwsdp-2.0\saaj\lib
C:\Sun\tomcat50-jwsdp\saaj\lib

6. Modify C:\examples\common\build.properties for the first four


lines as follows:

tutorial.home=C:
tutorial.install=${tutorial.home}
username=hxu
password=12345

where "hxu" and "12345" are the username and password for the
Tomcat server.

7. Build server:
cd C:\examples\jaxrpc\helloservice
ant build

Start Tomcat from JWSDP 2.0

Deploy server:
ant deploy

Note: If application already exists at path /hello-jaxrpc, you


should use the
command "ant undeploy" to undeploy the web service first.

Verify the deployment:


To verify that the service has been successfully deployed, open a
browser window
and specify the service endpoint's URL as follows:

http://localhost:8080/hello-jaxrpc/hello?WSDL
You should get the following display.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

8. Build client:
cd C:\examples\jaxrpc\dynamicproxy
ant build

Run client:
ant run

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

(ii) Describe on Simple Object Access Protocol.

XML Soap
 SOAP stands for Simple Object Access Protocol
 SOAP is an application communication protocol
 SOAP is a format for sending and receiving messages
 SOAP is platform independent
 SOAP is based on XML
 SOAP is a W3C recommendation

Why SOAP?

It is important for web applications to be able to communicate over the


Internet.

The best way to communicate between applications is over HTTP,


because HTTP is supported by all Internet browsers and servers. SOAP
was created to accomplish this.

SOAP provides a way to communicate between applications running on


different operating systems, with different technologies and
programming languages.

SOAP Building Blocks

A SOAP message is an ordinary XML document containing the following


elements:

 An Envelope element that identifies the XML document as a


SOAP message
 A Header element that contains header information
 A Body element that contains call and response information
 A Fault element containing errors and status information

Syntax Rules

Here are some important syntax rules:

 A SOAP message MUST be encoded using XML


 A SOAP message MUST use the SOAP Envelope namespace
 A SOAP message must NOT contain a DTD reference
 A SOAP message must NOT contain XML Processing Instructions

12. (i) Discuss the XMLHttpRequest Object with example.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

AJAX - The XMLHttpRequest Object


The keystone of AJAX is the XMLHttpRequest object.

The XMLHttpRequest Object


All modern browsers support the XMLHttpRequest object.

The XMLHttpRequest object can be used to exchange data with a


server behind the scenes. This means that it is possible to update
parts of a web page, without reloading the whole page.

Create an XMLHttpRequest Object


All modern browsers (Chrome, Firefox, IE7+, Edge, Safari Opera) have
a built-in XMLHttpRequest object.

Syntax for creating an XMLHttpRequest object:

variable = new XMLHttpRequest();


Example
var xhttp = new XMLHttpRequest();

Access Across Domains


For security reasons, modern browsers do not allow access across
domains.

This means that both the web page and the XML file it tries to load,
must be located on the same server.

The examples on W3Schools all open XML files located on the


W3Schools domain.

If you want to use the example above on one of your own web pages,
the XML files you load must be located on your own server.

Example
if (window.XMLHttpRequest) {
// code for modern browsers
xmlhttp = new XMLHttpRequest();
} else {
// code for old IE browsers

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");


}

(ii) Describe about Java web service basics.

JAX-WS Example RPC Style


Creating JAX-WS example is a easy task because it requires no extra
configuration settings.

JAX-WS API is inbuilt in JDK, so you don't need to load any extra jar file for it.
Let's see a simple example of JAX-WS example in RPC style.

There are created 4 files for hello world JAX-WS example:

1. HelloWorld.java
2. HelloWorldImpl.java
3. Publisher.java
4. HelloWorldClient.java

The first 3 files are created for server side and 1 application for client side.

JAX-WS Server Code


File: HelloWorld.java

1. package com.javatpoint;
2. import javax.jws.WebMethod;
3. import javax.jws.WebService;
4. import javax.jws.soap.SOAPBinding;
5. import javax.jws.soap.SOAPBinding.Style;
6. //Service Endpoint Interface
7. @WebService
8. @SOAPBinding(style = Style.RPC)
9. public interface HelloWorld{
10. @WebMethod String getHelloWorldAsString(String name);
11. }

File: HelloWorldImpl.java

1. package com.javatpoint;
2. import javax.jws.WebService;
3. //Service Implementation
4. @WebService(endpointInterface = "com.javatpoint.HelloWorld")

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

5. public class HelloWorldImpl implements HelloWorld{


6. @Override
7. public String getHelloWorldAsString(String name) {
8. return "Hello World JAX-WS " + name;
9. }
10. }

File: Publisher.java

1. package com.javatpoint;
2. import javax.xml.ws.Endpoint;
3. //Endpoint publisher
4. public class HelloWorldPublisher{
5. public static void main(String[] args) {
6. Endpoint.publish("http://localhost:7779/ws/hello", new HelloWorldIm
pl());
7. }
8. }

How to view generated WSDL


After running the publisher code, you can see the generated WSDL file by visiting
the URL:

1. http://localhost:7779/ws/hello?wsdl

JAX-WS Client Code


File: HelloWorldClient.java

1. package com.javatpoint;
2. import java.net.URL;
3. import javax.xml.namespace.QName;
4. import javax.xml.ws.Service;
5. public class HelloWorldClient{
6. public static void main(String[] args) throws Exception {
7. URL url = new URL("http://localhost:7779/ws/hello?wsdl");
8.
9. //1st argument service URI, refer to wsdl document above
10. //2nd argument is service name, refer to wsdl document above
11. QName qname = new QName("http://javatpoint.com/", "HelloWorld
ImplService");
12. Service service = Service.create(url, qname);
13. HelloWorld hello = service.getPort(HelloWorld.class);

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

14. System.out.println(hello.getHelloWorldAsString("javatpoint rpc"));


15. }
16. }

Output:

Hello World JAX-WS javatpoint rpc

(i) Explain in detail about SOAP encoding.

• For transfer between client and server in a SOAP message, we encode them in
XML.
SOAP Encoding is an extension of the SOAP framework specification that defines how a
data value should be encoded in an XML format. SOAP Data Model is defined as an
adjunct in SOAP 1.2 specification.
SOAP encoding offers the following rules to convert any data value defined in SOAP
data model into XML format. Converting a data value into XML format is called
serialization or encoding.
Rule 1. A simple value node with a labeled inbound edge will be serialized into a single
XML element with the edge's label as the element's name and node value as the
element's text content.
Rule 2. When serializing a node into an XML element, an "xsi:type" attribute can be
added to specify the value type of this note. For more information on "xsi:type", see the
other sections in this book.
Rule 3. A compound value node with labeled outbound edges, a data structure, will be
serialized into a single XML element with child elements. One outbound edge will be
serialized into one child element with element's name equal to the edge's label. The
13. order of child elements is not significant.
Rule 4. A compound value node with non-labeled outbound edges, a data array, will be
serialized into a single XML element with child elements. One outbound edge will be
serialized into one child element with element's name equal to any label as long as it's
the same for all child elements. The order of child elements signifies the position values
of outbound edges.
Rule 5. When serializing an array, an "enc:itemType" attribute can be added to specify
the value type of its sub nodes, and an "enc:arraySize" attribute can be added to specify
the number of values in the array.

(ii) Point out the RPC representation model.

What Is JAX-RPC?
JAX-RPC stands for Java API for XML-based RPC. It's an API for building
Web services and clients that used remote procedure calls (RPC) and XML.
Often used in a distributed client/server model, an RPC mechanism enables
clients to execute procedures on other systems.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

In JAX-RPC, a remote procedure call is represented by an XML-based


protocol such as SOAP. The SOAP specification defines envelope structure,
encoding rules, and a convention for representing remote procedure calls
and responses. These calls and responses are transmitted as SOAP messages
over HTTP. In this release, JAX-RPC relies on SOAP 1.1 and HTTP 1.1.

Although JAX-RPC relies on complex protocols, the API hides this


complexity from the application developer. On the server side, the
developer specifies the remote procedures by defining methods in an
interface written in the Java programming language. The developer also
codes one or more classes that implement those methods. Client programs
are also easy to code. A client creates a proxy, a local object representing
the service, and then simply invokes methods on the proxy.

With JAX-RPC, clients and Web services have a big advantage--the


platform independence of the Java programming language. In addition,
JAX-RPC is not restrictive: a JAX-RPC client can access a Web service that
is not running on the Java platform and vice versa. This flexibility is
possible because JAX-RPC uses technologies defined by the World Wide
Web Consortium (W3C): HTTP, SOAP, and the Web Service Description
Language (WSDL). WSDL specifies an XML format for describing a
service as a set of endpoints operating on messages.

Explain the structure of a WSDL document, its elements and their


purposes with appropriate examples.

A WSDL document defines services as collections of network endpoints,


or ports. In WSDL, the abstract definition of endpoints and messages is
separated from their concrete network deployment or data format bindings.
This allows the reuse of abstract definitions: messages, which are abstract
descriptions of the data being exchanged, and port types which are abstract
14. collections of operations. The concrete protocol and data format
specifications for a particular port type constitutes a reusable binding. A
port is defined by associating a network address with a reusable binding,
and a collection of ports define a service. Hence, a WSDL document uses
the following elements in the definition of network services:

 Types– a container for data type definitions using some type system
(such as XSD).
 Message– an abstract, typed definition of the data being
communicated.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 Operation– an abstract description of an action supported by the


service.
 Port Type–an abstract set of operations supported by one or more
endpoints.
 Binding– a concrete protocol and data format specification for a
particular port type.
 Port– a single endpoint defined as a combination of a binding and a
network address.
 Service– a collection of related endpoints.

In addition, WSDL defines a common binding mechanism. This is used to


attach a specific protocol or data format or structure to an abstract message,
operation, or endpoint. It allows the reuse of abstract definitions.

WSDL Document Example

The following example shows the WSDL definition of a simple service


providing stock quotes. The service supports a single operation called
GetLastTradePrice, which is deployed using the SOAP 1.1 protocol over
HTTP. The request takes a ticker symbol of type string, and returns the price
as a float. A detailed description of the elements used in this definition can
be found in Section 2 (core language) and Section 3 (SOAP binding).

This example uses a fixed XML format instead of the SOAP encoding (for
an example using the SOAP encoding, see Example 4).

Example 1 SOAP 1.1 Request/Response via HTTP


<?xml version="1.0"?>
<definitions name="StockQuote"

targetNamespace="http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">

<types>
<schema targetNamespace="http://example.com/stockquote.xsd"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="TradePriceRequest">
<complexType>
<all>
<element name="tickerSymbol" type="string"/>
</all>
</complexType>
</element>
<element name="TradePrice">
<complexType>
<all>
<element name="price" type="float"/>

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

</all>
</complexType>
</element>
</schema>
</types>

<message name="GetLastTradePriceInput">
<part name="body" element="xsd1:TradePriceRequest"/>
</message>

<message name="GetLastTradePriceOutput">
<part name="body" element="xsd1:TradePrice"/>
</message>

<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>

<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">


<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetLastTradePrice">
<soap:operation soapAction="http://example.com/GetLastTradePrice"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort" binding="tns:StockQuoteBinding">
<soap:address location="http://example.com/stockquote"/>
</port>
</service>

</definitions>

PAR
T–C
Q.No Questions
Create an XML HttpRequest to retrieve data from an XML file and
display the data in an HTML table. The data to be retrieved is a
collection of stationary items stored in an XML file.

1.
The XML Document Used

INPUT: XML file called "cd_catalog.xml".

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

Display XML Data in an HTML Table

This example loops through each <CD> element, and displays the
values of the <ARTIST> and the <TITLE> elements in an HTML table:

Example
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse:collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>

<table id="demo"></table>

<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", "cd_catalog.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Artist</th><th>Title</th></tr>";
var x = xmlDoc.getElementsByTagName("CD");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValu
e +
"</td><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue
+
"</td></tr>";

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

}
document.getElementById("demo").innerHTML = table;
}
</script>

</body>
</html>

OUTPUT
Artist Title
Bob Dylan Empire Burlesque
Bonnie Tyler Hide your heart
Dolly Parton Greatest Hits
Gary Moore Still got the blues
Eros Ramazzotti Eros
Bee Gees One night only
Dr.Hook Sylvias Mother
Summarize Ajax Client server architecture in detail.

What is AJAX?
AJAX = Asynchronous JavaScript And XML.

AJAX is not a programming language.

AJAX just uses a combination of:

2.  A browser built-in XMLHttpRequest object (to request data from a web server)
 JavaScript and HTML DOM (to display or use the data)

AJAX is a misleading name. AJAX applications might use XML to transport data, but it
is equally common to transport data as plain text or JSON text.

AJAX allows web pages to be updated asynchronously by exchanging data with a web
server behind the scenes. This means that it is possible to update parts of a web page,
without reloading the whole page.

How AJAX Works

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 1. An event occurs in a web page (the page is loaded, a button is clicked)


 2. An XMLHttpRequest object is created by JavaScript
 3. The XMLHttpRequest object sends a request to a web server
 4. The server processes the request
 5. The server sends a response back to the web page
 6. The response is read by JavaScript
 7. Proper action (like page update) is performed by JavaScript

Give the basic structure of a WSDL and show how they are used to
create, publish, test and describe web services.

Structure of a WSDL Document


3. Web Services Description Language (WSDL) is an XML grammar for
describing network services as collections of communication
endpoints capable of exchanging messages. The diagram below
illustrates the elements that are present in a WSDL document, and
indicates their relationships. To see an example of how this is
implemented in a WSDL document, see Example of a WSDL
Document .

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

WSDL Document Elements

A WSDL document has a definitions element that contains the other


five elements, types, message, portType, binding and service. The
following sections describe the features of the generated client code.

WSDL supports the XML Schemas specification (XSD) as its type


system.

definitions
Contains the definition of one or more services. JDeveloper
generates the following attribute declarations for this section:

 name is optional.
 targetNamespace is the logical namespace for information
about this service. WSDL documents can import other
WSDL documents, and setting targetNamespace to a
unique value ensures that the namespaces do not clash.
 xmlns is the default namespace of the WSDL document,
and it is set to http://schemas.xmlsoap.org/wsdl/.
 All the WSDL elements, such
as <definitions>, <types> and <message> reside in this
namespace.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 xmlns:xsd and xmlns:soap are standard namespace


definitions that are used for specifying SOAP-specific
information as well as data types.
 xmlns:tns stands for this namespace.
 xmlns:ns1 is set to the value of the schema targetNamespace,
in the <types> section.

Compare and contrast the additional web application architecture


and AJAX Based web application architecture.
Traditional Web Applications vs. Ajax Applications

The following highlights the key differences between traditional web


applications and Ajax-based web applications.

Traditional Web Applications


 Figure 15.1 presents the typical interactions between the client and
the server in a tradi-tional web application, such as one that uses a
4.
user registration form.
 First, the user fills in the form’s fields, then submits the form (Fig.
15.1, Step 1). The browser generates a re-quest to the server, which
receives the request and processes it (Step 2).
 The server generates and sends a response containing the exact page
that the browser will render (Step 3), which causes the browser to
load the new page (Step 4) and temporarily makes the browser win-
dow blank. Note that the client waits for the server to respond
and reloads the entire page with the data from the response (Step 4).
 While such a synchronous request is being processed on the server,
the user cannot interact with the client web page.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

 Frequent long periods of waiting, due perhaps to Internet


congestion, have led some users to refer to the World Wide Web as
the “World Wide Wait.”
 If the user interacts with and submits an-other form, the process
begins again (Steps 5–8).

This model was originally designed for a web of hypertext


documents—what some people call the “brochure web.”
As the web evolved into a full-scale applications platform, the model
shown in Fig. 15.1 yielded “choppy” application performance.
Every full-page refresh required users to re-establish their
understanding of the full-page contents.
Users began to demand a model that would yield the responsive feel of
desktop applications.

Ajax Web Applications

 Ajax applications add a layer between the client and the server to
manage communication between the two (Fig. 15.2). When the user
interacts with the page, the client creates an XMLHttpRequest object
to manage a request (Step 1).
 The XMLHttpRequest object sends the request to the server (Step 2)
and awaits the response.
 The requests are asynchronous, so the user can continue interacting
with the application on the client-side while the server processes the

https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com

earlier request concurrently. Other user interactions could result in


addition-al requests to the server (Steps 3 and 4).
 Once the server responds to the original request (Step 5),
the XMLHttpRequest object that issued the request calls a client-side
function to process the data returned by the server.
 This function—known as a callback function— uses partial
page updates (Step 6) to display the data in the existing web
page without re-loading the entire page. At
the same time, the server may be responding to the second re-quest
(Step 7) and the client-side may be starting to do another partial page
update (Step 8).
 The callback function updates only a designated part of the page.
 Such partial page up-dates help make web applications more
responsive, making them feel more like desktop applications.
 The web application does not load a new page while the user
interacts with it.

https://play.google.com/store/apps/details?id=com.sss.edubuzz360

You might also like