0% found this document useful (0 votes)
19 views19 pages

Java SOAP Web Services Example Guide

The document provides an overview of XML web services using Java, highlighting the distinction between SOAP and REST web services. It explains the characteristics of each type, their differences, and includes a practical example of creating a SOAP web service in Java using Netbeans. Additionally, it outlines the steps for project creation, deployment, and testing of the web service.
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)
19 views19 pages

Java SOAP Web Services Example Guide

The document provides an overview of XML web services using Java, highlighting the distinction between SOAP and REST web services. It explains the characteristics of each type, their differences, and includes a practical example of creating a SOAP web service in Java using Netbeans. Additionally, it outlines the steps for project creation, deployment, and testing of the web service.
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

| Java XML Web Services 24 |

XML WEB SERVICES USING JAVA

WEB SERVICES
• It is a type of web application which is used to share the message
between client and server (Communication between two devices on a
network)
• Unlike web applications, the main benefit of web service supports the
code reusability. A single web service can be used by different kinds of
applications
• The main component of a web service is the data which is shared
between client and server
• It is a client server application for creating communication between two
devices over network for exchanging data

TYPES OF WEB SERVICES


• Web services come under two categories. They are
1. SOAP Based Services (XML Services)
2. REST Based Services
• Both services are two different ways to connect applications with server-
side data

1
| Java XML Web Services 24 |

1. SOAP Web Services (XML Web Services)


• SOAP stands for Simple Object Access Protocol
• This is XML based protocol for designing and developing web services.
• It is a platform and language independent as it is XML based
• It is an open standard protocol and provides data transport for web
services (Web services use SOAP protocol for sending the XML data
between applications)
2. REST Web Services (RESTful Web Services)
• REST stands for REpresentational State Transfer
• It is an architectural style for developing web services
• It is most popular web services on current trends
• Web services that implement REST architecture are called as RESTful
web services
• It is designed specifically for the components like media components,
files or objects on a particular hardware
DIFFERENCES BETWEEN SOAP AND REST WEB SERVICES
S.N SOAP Services REST Services
1. SOAP stands for simple object REST stands for
access protocol (Structured representational state transfer.
protocol)
2. It is a protocol REST is an architectural style
3. It only supports XML format It supports various formats like
HTML, XML, JSON, Plain Text
etc,.
4. SOAP needs more bandwidth for its REST doesn’t need more
usage bandwidth
5. JAX-WS is the java API for SOAP JAX-RS is the java API for
web services REST
2
| Java XML Web Services 24 |

6. It is more secure than REST It is less secure than SOAP


7. Resources – XML & HTTP Resources – HTTP
8. It is used to transport data in XML Here it is used to transport
format data in JSON format which is
based on URI.
9. As it is XML based, it works with It works with HTTP GET,
WSDL (Web Service Description POST, PUT, DELETE methods
Language)
10. It can’t use REST because it is a REST can use SOAP web
protocol services and it can use any
protocols like HTTP, SOAP
11. It uses service interfaces to expose It uses the URI (Uniform
the business logic Resource Identity) to expose
the business logic
12. It is less preferred than REST It is most preferred than SOAP.
It is most popular web services
on recent days

3
| Java XML Web Services 24 |

I. EXAMPLE OF XML / SOAP WEB SERVICES IN JAVA


IDE used : Netbeans 18
Application Type : Java Web
Server Tested : Glassfish Server 5
Type of Web Services : XML
JDK Version : 1.8
J2EE Version : J2EE 8
Deployment Mode : Server Side Only

STEP 1 – CREATE A NEW PROJECT IN NETBEANS 18

4
| Java XML Web Services 24 |

STEP 2 – DETAILS OF PROJECT NAME & LOCATION

5
| Java XML Web Services 24 |

STEP 3 – SERVER SELECTION

6
| Java XML Web Services 24 |

STEP 4 – FRAMEWORK SELECTION - OPTIONAL

7
| Java XML Web Services 24 |

VERIFICATION OF NEWLY CREATED PROJECT IN NETBEANS

8
| Java XML Web Services 24 |

2. SOURCE CODE
([Link])
package tp;
import [Link];
import [Link];
import [Link];
@WebService(serviceName = "NewWebService")
public class NewWebService
{
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
@WebMethod()
public String Add(int a, int b)
{
int c=a+b;
return "Sum is: "+[Link](c);
}
@WebMethod()
public String Sub(int a, int b)
{
int c=a-b;
return "Sub is: "+[Link](c);
}
@WebMethod()
public String Mul(int a, int b)
{
int c=a*b;
9
| Java XML Web Services 24 |

return "Mul is: "+[Link](c);


}
@WebMethod()
public String Div(int a, int b)
{
int c=a/b;
return "Div is: "+[Link](c);
}
}

10
| Java XML Web Services 24 |

3. OUTPUT
3.1 DEPLOYING THE PROJECT BEFORE TESTING THE WEB SERVICE
→ RIGHT CLICK ON THE CURRENT PROJECT AND SELECT DEPLOY
OPTION

11
| Java XML Web Services 24 |

3.2 DEPLOYED RESULT IN NETBEANS TERMINAL

12
| Java XML Web Services 24 |

3.3 DEPLOYED RESULT IN GLASSFISH SERVER

13
| Java XML Web Services 24 |

3.4 DEPLOYED RESULT IN GLASSFISH SERVER – (Continue)

14
| Java XML Web Services 24 |

3.5 RUNNING THE WEB SERVICE

15
| Java XML Web Services 24 |

3.6 HOME PAGE OF WEB SERVICE – LIST OF AVAILABLE SERVICES

16
| Java XML Web Services 24 |

3.7 TESTING WEB SERVICES – ADD WEB METHOD – SUBMISSION OF


DYNAMIC INPUTS

17
| Java XML Web Services 24 |

3.8 RESULT – XML INTERFACE

18
| Java XML Web Services 24 |

3.9 RESULT – XML – SOAP REQUEST & SOAP RESPONSE

19

Common questions

Powered by AI

SOAP web services enable code reusability across different applications by adhering to a standardized protocol, which is platform and language independent. This allows diverse applications to communicate and share data through established XML-based messaging, enabling shared functionality regardless of the underlying programming environment .

The SOAP message structure manages complexity through its standardized XML format, which encapsulates a comprehensive envelope with dedicated elements for header, body, and fault. This structure allows SOAP messages to support complex operations, ensure detailed data integrity, and maintain protocol-specific metadata. REST lacks this complexity management capability, as it relies on simpler, stateless HTTP methods without intrinsic messaging format complexity, making SOAP suitable for scenarios requiring intricate data interfacing and transaction coordination .

SOAP web services handle errors through comprehensive fault elements within the SOAP protocol, ensuring structured error reporting and detailed fault information as part of the response message. In contrast, REST web services utilize standard HTTP status codes to communicate errors; this method is more simplistic but relies on client-side understanding of the HTTP response statuses for appropriate error handling, potentially lacking the detailed error descriptors found in SOAP exceptions .

The preference for REST over SOAP in contemporary web service design is steeped in REST's simplicity, flexibility, and compatibility with web technologies like JSON and HTTP. REST's architectural style reduces bandwidth usage, simplifies integration with web browsers, and aligns well with modern development frameworks. Together with REST's support for stateless operations and a wide range of data formats, these advantages have led to its increased popularity over the more rigid and bandwidth-intensive SOAP protocol .

SOAP is a protocol and primarily uses XML for data transport, requiring more bandwidth due to its structured format, and typically working with WSDL (Web Service Description Language). It is considered more secure. REST, on the other hand, is an architectural style that supports various data formats like HTML, XML, JSON, and Plain Text. REST is generally less bandwidth-intensive and operates with HTTP methods such as GET, POST, PUT, and DELETE. REST can utilize SOAP services while SOAP cannot use REST services .

RESTful web services are more flexible than SOAP-based services as they support multiple data formats (HTML, XML, JSON, Plain Text) compared to SOAP's XML-only format. REST operates through simple HTTP requests like GET, POST, PUT, DELETE, which are more aligned with modern web usage patterns. This architectural style can also adopt SOAP services and is generally preferred in recent trends due to its simplicity and lower bandwidth requirement .

Creating a SOAP web service in Java using Netbeans involves several steps: starting with creating a new project, configuring the project details and server settings, and writing the web service code. For example, the class 'NewWebService' includes methods like 'hello', 'Add', 'Sub', 'Mul', and 'Div', each functioning as web methods exposed via SOAP. After coding, the project is deployed on a server like Glassfish for testing, with methods accessible through SOAP requests and responses, as demonstrated by the SOAP interface and dynamic input submission .

An organization might choose SOAP-based services over REST due to SOAP's superior security features, support for complex transactions, and thoroughness in enterprise-level integration requirements. SOAP's ability to handle asynchronous operations and its reliance on advanced standards (like WS-Security) make it a suitable choice for high-security environments, heavyweight distributed computing, and scenarios requiring robust transactional support, despite REST's trendier appeal .

SOAP services are inherently more secure than REST because SOAP supports protocols like WS-Security, which provide integrated security features for message protection, authentication, and transaction management. RESTful services, in contrast, rely on HTTPS for basic transport-level security and must implement additional security measures for equivalent data protection and transaction security, making SOAP more suitable for applications where security is a high priority .

Java API JAX-WS is advantageous for SOAP web services as it provides comprehensive support for XML-based messaging, adheres to the protocol's needs, and allows detailed service definition and communication. Conversely, JAX-RS is tailored for RESTful web services, leveraging their architectural style to simplify web service development with support for multiple data formats and HTTP methods, facilitating modern, lightweight web service creation .

You might also like