Often you need to make a decision how your services will accept the message payload from calling services or clients. The two popular ways to implement messaging between services is SOAP and REST.
SOAP or Simple Object Access Protocol relies on a very specific message format to pass on the information. It uses XML based messages, and a message usually contains an envelop, headers, body and fault part. It provides built in error handling, when a request has an error, response would give proper error details.
POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 SOAPAction: "http://www.w3.org/2003/05/soap-envelope" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.example.org"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice> <m:StockName>T</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
Element | Description | Required |
---|---|---|
Envelope | Identifies the XML document as a SOAP message. | Yes |
Header | Contains header information. | No |
Body | Contains call and response information. | Yes |
Fault | Provides information about errors that occurred while processing the message. | No |
A discussion about SOAP is incomplete without referring to WSDL. Web Service Description Language is an XML based document which gives details regarding the WebService. How many services it provides, how to invoke the service, what kind of request and response is expected, and so on. WSDL is shared with calling or client services, which can use it to understand the provider service structure. Many languages have automated tools or libraries to generate client code automatically using the WSDL.
WSDL 1.1 Term | WSDL 2.0 Term | Description |
---|---|---|
Service | Service | Contains a set of system functions that have been exposed to the Web-based protocols. |
Port | Endpoint | Defines the address or connection point to a Web service. It is typically represented by a simple HTTP URL string. |
Binding | Binding | Specifies the interface and defines the SOAP binding style (RPC/Document) and transport (SOAP Protocol). The binding section also defines the operations. |
PortType | Interface | Defines a Web service, the operations that can be performed, and the messages that are used to perform the operation. |
Operation | Operation | Defines the SOAP actions and the way the message is encoded, for example, “literal.” An operation is like a method or function call in a traditional programming language. |
Message | n/a | Typically, a message corresponds to an operation. The message contains the information needed to perform the operation. Each message is made up of one or more logical parts. Each part is associated with a message-typing attribute. The message name attribute provides a unique name among all messages. The part name attribute provides a unique name among all the parts of the enclosing message. Parts are a description of the logical content of a message. In RPC binding, a binding may reference the name of a part in order to specify binding-specific information about the part. A part may represent a parameter in the message; the bindings define the actual meaning of the part. Messages were removed in WSDL 2.0, in which XML schema types for defining bodies of inputs, outputs and faults are referred to simply and directly. |
Types | Types | Describes the data. The XML Schema language (also known as XSD) is used (inline or referenced) for this purpose. |
REST or Representational State Transfer is an architectural style rather than a protocol which lets one use HTTP verbs to communicate among services. It helps making the communication easier as there is no restriction in format of data being sent. Also it is often easier to implement and lightweight as no need for XML parsing on client and provider side.
HTTP method | Description |
---|---|
GET | Get a representation of the target resource’s state. |
POST | Let the target resource process the representation enclosed in the request. |
PUT | Set the target resource’s state to the state defined by the representation enclosed in the request. |
DELETE | Delete the target resource’s state. |