Web Service - SOAP

What is Web Service

“A Web service is a method of communication between two electronic devices over a network.”

Common Type: SOAP web service, RESTful web service

Web Service is used primarily as a means for businesses to communicate with each other and with clients, Web services allow organizations to communicate data without intimate knowledge of each other’s IT systems behind the firewall.

总结来说,就是公司内的部门A和部门B,或者公司X和公司Y,为了某一些数据互通,开发的一个数据通信模块。

Web Services Example

Register/Ordering

Consider a simple account-management and order processing system. The accounting personnel use a client application built with Visual Basic or JSP to create new accounts and enter new customer orders.

The processing logic for this system is written in Java and resides on a Solaris machine, which also interacts with a database to store information.

Client(VB) -> account registration
	-> SOAP ->
DB Command -> Server & DB(Java)

The steps to perform this operation are as follows:

http://www.tutorialspoint.com/webservices/what_are_web_services.htm

What is SOAP

Simple Object Access Protocol

SOAP Structure

In the example of SOAP web service

web service

SOAP是比较早期的Web Service解决方案,后来慢慢就淘汰了,主要原因是“重”,开发起来复杂,学习成本高。

这个“重”主要体现在几个方面:

总结来看,SOAP参考了很多Java API的编程思想,比如RMI/RPC,以及JNDI等等。它想成为一个非常规范的web service框架,但是有点over design了,开发起来比较麻烦,是一个技术发展的中间产物。现在,RESTful基本已经替代它了。

个人认为,REST能战胜SOAP的很大一个原因是,它没有重复造轮子,而是使用了现有的轮子,以一种新的方式组合起来,且足够简洁,直接描述出了web service的本质。

SOAP Message

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

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>
  ...
</soap:Header>

<soap:Body>
  ...
  <soap:Fault>
  ...
  </soap:Fault>
</soap:Body>

</soap:Envelope>

WSDL

Web Services Description Language It is just a simple XML document. The description includes the name of the service, the location of the service, and ways to communicate with the service.

Document Structure

<definitions>

<types>
  data type definitions........
</types>

<message>
  definition of the data being communicated....
</message>

<portType>
  set of operations......
</portType>

<binding>
  protocol and data format specification....
</binding>

</definitions>

UDDI

Universal Description, Discovery and Integration

a directory service where businesses can register and search for Web services

Code Example

Create a Web Service with Server & Client

JAX-WS

Steps:

Eclipse

Spring

Fork me on GitHub