Microservice SOAP API - yibinericxia/documents GitHub Wiki

SOAP (Simple Object Access Protocol)

SOAP web service (WS) is used in traditional applications which uses XML as a more structural data format with built-in ACID compliance, so it is good for candidates requiring high data integrity between client and server even at database level, such as private APIs of financial systems, which maintain previous requests state for new request processing. It is a function-driven protocol with rigid communication rules/standards:

  • WSDL describes scopes and functions/operations
  • WS-Security for security measures, like using unique identifiers called tokens
  • WS-Addressing have routing information as metadata
  • WS-ReliableMessaging handles error messaging

Pros

  • Security WS-Security uses additional header content to ensure the designated process in the specified server get the content.
  • Reliability built-in error handling makes more reliable than REST API

Cons

  • Payload larger payload compared with REST API makes it slower to transmit.

  • Scaling due to state handling

JAXB (Java Architecture for XML Binding) for XML

Powerful library to bind XML data to Java objects

  1. automatic generation of Java class from XML schemas or existing XML documents
  2. easy marshalling Java objects to XML and unmarshalling XML to Java objects
// marshal Java object to XML header
JAXBContext context = JAXBContext.newInstance(MyObject.calss);
Marshaller marshaller = context.createMarchaller();
marshaller.setProbperty(Marchaller.JAXB_FREGMENT, true);
JAXBElement header = new JAXBElement(...);
FileWriter writer = new FileWriter(file);
marshaller.marshal(header, writer);
...

// 
Unmarshaller unmarshaller = context.createUnmarshaller();
MyObject = unmarshaller.unmarshal(inputStream);