What is SOAP?
SOAP is an XML-based protocol for accessing web services over HTTP. It has some specifications that can be used for all applications.
SOAP is known as Simple Object Access Protocol, but was later shortened to SOAP v1.2. SOAP is a protocol, or in other words, a definition of how web services communicate with each other or with the client applications that call them.
SOAP was developed as an intermediate language so that applications built in different programming languages can easily communicate with each other and avoid extreme development effort.
In this SOAP web services tutorial, you will learn:
- Introduction to SOAP
- SOAP Benefits
- SOAP Building Blocks
- SOAP message structure
- About SOAP Element
- SOAP communication model
- SOAP Practical Example
Introduction to SOAP
In today's world, there are a large number of applications built on top of different programming languages. For example, there may be a web application designed in Java, another in .Net, and another in .NetPHP.
Sharing data between applications is critical in today's connected world. However, the exchange of data between these heterogeneous applications would be complex. So does the complexity of the code to perform this data exchange.
One of the ways to combat this complexity is to use XML (Extensible Markup Language) as an intermediate language for data exchange between applications.
Any programming language can understand XML markup language. Therefore, XML was used as the underlying medium for data exchange.
But there are no uniform guidelines for the use of XML in all programming languages for data interchange. This is where SOAP software comes into play.
SOAP was designed to work with XML over HTTP and has a kind of specification that can be used in all applications. In the following chapters we will go into more detail about the SOAP protocol.
SOAP is the protocol used to exchange data between applications. Below are some of the reasons why SOAP is used.
- When developing SOAP-based web services, you need a language that can be used for web services to communicate with client applications. SOAP is the perfect medium designed to achieve this purpose. This protocol is also recommended by the W3C consortium, the umbrella organization for all web standards.
- SOAP is a lightweight protocol used to exchange data between applications. Notice the keyword 'hell.” Since SOAP programming is based on the XML language, which itself is a lightweight data interchange language, SOAP as a protocol also falls into the same category.
- SOAP is designed to be platform and operating system independent. So, the SOAP protocol can run applications based on any programming language on both Windows and Windows.linuxPlatform.
- Works with the HTTP protocol: SOAP works with the HTTP protocol, which is the standard protocol used by all web applications. Therefore, no customization is required to run SOAP protocol-based web services to work on the World Wide Web.
SOAP Building Blocks
The SOAP specification defines something called "SOAP message', which is sent to the web service and the client application.
The following SOAP architecture diagram shows the different basic components of a SOAP message.
The SOAP message is nothing more than a pure XML document that contains the following components.
- An envelope element that identifies the XML document as a SOAP message: This is the container part of the SOAP message and is used to encapsulate all the details in the SOAP message. This is the root element in the SOAP message.
- A header element containing header information: The header element can contain information, such as authentication data, that can be used by the calling application. It may also contain the definition of complex types that might be used in the SOAP message. By default, the SOAP message can contain parameters, which can be simple types like strings and numbers, but can also be a complex object type.
Below is an example of a simple SOAP service of a complex type.
Suppose we want to send a structured data type that contains a combination of a "tutorial name" and a "tutorial description", then we would define the complex type as shown below.
The complex type is defined by the <xsd:complexType> element tag. All the required elements of the structure are then defined along with their respective data types in the complex type collection.
<xsd:complexType> <xsd:sequence> <xsd:element name="Tutorial Name" type="string"/> <xsd:element name="Tutorial Description" type="string"/> </xsd:sequence> </xsd:tipocomplejo>
- A body element containing call and response information: This element contains the actual data that needs to be sent between the web service and the calling application. Below is an example SOAP web service of the SOAP body that actually works on the complex type defined in the header section. Here is the tutorial name and the tutorial description response sent to the calling application that invokes this web service.
<soap:Body> <GetTutorialInfo><TutorialName>Web services</TutorialName> <TutorialDescription>All about web services</TutorialDescription> </GetTutorialInfo></soap:Body>
SOAP message structure
Note that SOAP messages are usually automatically generated by the web service when it is invoked.
Whenever a client application calls a method in the web service, the web service automatically generates a SOAP message with the required details of the data that is sent from the web service to the client application.
As discussed in the previous topic of this SOAP tutorial, a simple SOAP message has the following elements:
- Das Envelope-Element
- The header element and
- the element of the body
- The error element (optional)
Let's look at an example of a simple SOAP message below and see what the element actually does.
- As can be seen in the SOAP message above, the first part of the SOAP message is the Envelope element, which is used to encapsulate the entire SOAP message.
- The next element is the SOAP body, which contains the details of the actual message.
- Our message contains a web service called "Guru99WebService".
- The "Guru99Webservice" accepts a parameter of type 'int' and has the name TutorialID.
Now the above SOAP message is transmitted between the web service and the client application.
You can see how useful the above information is for the client application. The SOAP message tells the client application what the name of the web service is, what parameters it expects, and also the type of each parameter used by the web service.
About SOAP Element
The first bit of the building block is the SOAP envelope.
SOAP Envelope is used to encapsulate all the necessary details of the SOAP messages exchanged between the web service and the client application.
The SOAP envelope element is used to indicate the beginning and end of a SOAP message. This allows the client application that calls the web service to know when the SOAP message has finished.
The following points can be noted on the SOAP envelope element.
- Every SOAP message must have a root envelope element. A SOAP message must have an envelope element.
- Each Wrapper element must have at least one soap body element.
- If an Envelope element contains a Header element, it cannot contain more than one and must appear as the first child element of the Envelope before the Body element.
- The envelope changes as SOAP versions change.
- A v1.1 compliant SOAP processor will fail if it receives a message containing the v1.2 envelope namespace.
- A v1.2 compliant SOAP processor will generate a version mismatch error if it receives a message that does not contain the v1.2 envelope namespace.
The following is an example SOAP API from version 1.2 of the SOAP envelope element.
<?xml version="1.0"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope" SOAP-ENV:encodingStyle=" http: //www.w3.org/2001/12/soap-encoding"> <soap:Body> <Guru99WebService xmlns="http://tempuri.org/"> <TutorialID>int</TutorialID> </Guru99WebService> < /soap:Cuerpo></SOAP-ENV:Sobre>
the error message
When a request is made to a SOAP web service, the response returned can be either a success response or an error response. If a success is generated, the response from the server is always a SOAP message. However, when SOAP errors are generated, they are returned as HTTP 500 errors.
The SOAP error message consists of the following elements.
- <error code>– This is the code indicating the error code. The error code can be one of the following values
- SOAP-ENV:VersionMismatch – This occurs when an invalid namespace is found for the SOAP envelope element.
- SOAP-ENV: MustUnderstand: An immediate child element of the header element that had the mustUnderstand attribute set to '1' was not understood.
- SOAP-ENV:Client - The message was malformed or contained incorrect information.
- SOAP-ENV:Server: There was a problem with the server, so the message could not continue.
- <error string>- This is the text message detailing the error.
- <fault actor> (Optional)- This is a text string that identifies who caused the interrupt.
- <Detail>(Optional)– This is the element for application-specific error messages. So the application could have a specific error message for different business logic scenarios.
Example error message
Below is an example of an error message. The error is generated when the scenario where the client tries to call a method called TutorialID on the GetTutorial.
The following error message is generated if the method does not exist in the defined class.
<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Sobre xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi=" http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Cuerpo> <SOAP-ENV:Error> <faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode> <faultstring xsi:type="xsd:string"> Fehler beim Auffinden der Methode (GetTutorialID) in der Klasse (GetTutorial) </faultstring > < /SOAP-ENV:Error> </SOAP-ENV:Cuerpo></SOAP-ENV:Sobre>
When you run the above code, you get an error like "Error locating method (GetTutorialID) in class (GetTutorial)".
SOAP communication model
All SOAP communication is done over the HTTP protocol. Before SOAP, many web services used the standard RPC (Remote Procedure Call) style for communication. This was the easiest way to communicate, but it had many limitations.
Now, in this SOAP API tutorial, let's look at the following diagram to see how this communication works. In this example, suppose the server hosts a web service that has two methods exposed as
- get staff– This would get all the details of the employees
- setEmployee– This would set the value of details like employees, salary, etc. consequently.
With normal RPC-style communication, the client would simply call the methods on its request and send the necessary parameters to the server, and the server would send back the desired response.
The above communication model has the following severe limitations
- Not language independent– The server hosting the methods would be in a specific programming language, and calls to the server would normally only be made in that programming language.
- Not the standard protocol– When calling the remote procedure, the call is not made using the standard protocol. This was a problem because almost all communication over the Internet had to be done over the HTTP protocol.
- firewall– Since RPC calls do not use the normal protocol, separate ports must be opened on the server so that the client can communicate with the server. Normally, all firewalls would block this type of traffic, and there was usually a lot of configuration required to ensure that this type of client-server communication would work.
To overcome all of the above limitations, SOAP would use the following communication model
- The client formats the procedure call information and any arguments into a SOAP message and sends it to the server as part of an HTTP request. This process of encapsulating the data in a SOAP message was calledmaneuvers.
- The server would then unpack the message sent by the client, see what the client requested, and then send the appropriate response to the client as a SOAP message. The practice of unpacking a request sent by the client is calledDemarschallung.
SOAP Practical Example
Now let's look at a practical SOAP example in this SoapUI tutorial.
Probably one of the best ways to see how SOAP messages are generated is to see a web service in action.
This topic discusses using the Microsoft.Net framework to create an ASMX web service. This type of web service is compatible with both SOAP version 1.1 and version 1.2.
ASMX web services automatically generate the WSDL (Web Services Definition Language) document. The calling client application requires this WSDL document so that the application knows what the web service is capable of.
In our example, we'll create a simple web service that will be used to return a string to the application that calls the web service.
This web service is hosted on aAsp.Netinternet application We then call the web service and see the result returned by the web service.
Visual Studio also shows us what SOAP message is being passed between the web service and the calling application.
The first requirement to configure our web service application, which can be done by following the steps below.
Make sure Visual Studio 2013 is installed on your system for this example.
Paso 1)The first step is to create an empty ASP.Net web application. In Visual Studio 2013, click the File->New Project menu option.
After clicking the New Project option, Visual Studio will show you another dialog where you can select the project type and provide the necessary project details. This is explained in the next step.
Paso 2)in this step
- Be sure to select them firstC#ASP.NET Web Application web template. The project must be of this type to create a SOAP Services project. If you select this option, Visual Studio performs the necessary steps to add the files required by each web-based application.
- Give your project a name, which in our case is webservice.asmx. Then be sure to specify a location where the project files will be saved.
You will then see the project file created in your solution explorer in Visual Studio 2013.
Paso 3)in this step
We will add a web service file to our project
- First right click on the project file as shown below
- Once you right-click on the project file, you will have the option to select the Add->Web Service (ASMX) option to add a web service file. Simply specify the name Tutorial Service for the web service name file.
stage 4)Add the following code to your Tutorial Service asmx file.
- This line of code specifies a name for your web service file. This is an important step because the client application can call the web service using the name of the web service.
- Typically, a class file is used to encapsulate the functionality of a web service. So, the class file contains the definition of all the web methods that provide some functionality to the client application.
- Here, [WebMethod] is an attribute that describes a function. The next step creates a function called Guru99WebService, but including this step of adding a [WebMethod] attribute ensures that this method can be called from a client application. If this attribute is not present, the method can never be called from a client application.
- Here we define a function called "Guru99WebService" that is used to return a string to the calling client application. This function is a web service that can be called from any client application.
- We use the return statement to return the string "This is a Guru99 web service" to the client application.
If the code runs successfully, you'll see the following output when you run your code in the browser.
- The output clearly shows that the name of our web service is "Guru99 Web Service", which is the result of naming our web service.
- We can also see that we can call the web service. When we click the Invoke button, we get the following response in the web browser.
the previous output,
- It clearly shows that calling the web method returns the string "This is a Guru99 web service".
- You can also use Visual Studio to view the SOAP message request and response generated when the above web service is invoked.
The SOAP request that is generated when the web service is called is shown below.
- The first part of the SOAP message is the Envelope element, discussed in previous chapters. This is the encapsulation element present in every SOAP message.
- The SOAP body is the next element and contains the actual details of the SOAP message.
- The third part is the element that indicates that we want to invoke the service called "Guru99WebService".
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <Guru99WebServiceResponse xmlns="http://tempuri.org/"> <Guru99WebServiceResult>String </Guru99WebServiceResult> </Guru99WebServiceResponse> </soap:Cuerpo></soap:Sobre>
- The first part of the SOAP message is the Envelope element, discussed in previous chapters. This is the encapsulation element present in every SOAP message.
- The SOAP body is the next element and contains the actual details of the SOAP message.
- The interesting part you'll see now is the string attribute. This tells the client application that the called web service is returning an object of type String. This is very useful as a client application, which would not otherwise know what the web service returns.
- SOAP is a protocol used to exchange data between applications built on differentprogramming languages.
- SOAP is based on the XML specification and works over the HTTP protocol. This makes it perfect for use in web applications.
- The basic components of SOAP consist of a SOAP message. Each SOAP message consists of an envelope element, a header, and a body element.
- The Envelope element is the required element in the SOAP message and is used to encapsulate all the data in the SOAP message.
- The header element can be used to contain information such as authentication information or the definition of complex data types.
- The body element is the main element that contains the definition of the web methods together with all the necessary parameter information.
You may like:
- What are web services? Architecture, types, example
- What is SOA? Principles of service-oriented architecture
- JSON Tutorial - Learn a Simple File Format with EXAMPLE
- SOA vs Microservices - difference between them
Simple Object Access Protocol (SOAP) is a lightweight XML-based protocol that is used for the exchange of information in decentralized, distributed application environments. You can transmit SOAP messages in any way that the applications require, as long as both the client and the server use the same method.What is a SOAP in web service? ›
SOAP is a messaging protocol for exchanging information between two computers based on XML over the internet. SOAP messages are purely written in XML which is why they are platform and language independent. A SOAP message contains: An Envelope that indicates the start and end of the message.What is SOAP explain the SOAP message format? ›
A SOAP message is an XML document that consists of a SOAP envelope, an optional SOAP header, and a SOAP body. The SOAP message header contains information that allows the message to be routed through one or more intermediate nodes before it reaches its final destination.How many communication protocols can be used to implement a SOAP message? ›
SOAP supports two possible communication styles: – remote procedure call (RPC) and – document (or message).How does SOAP protocol work? ›
How Does SOAP Work? The SOAP specification describes a standard, XML-based way to encode requests and responses, including: Requests to invoke a method on a service, including in parameters. Responses from a service method, including return value and out parameters.What is difference between HTTP and SOAP protocol? ›
SOAP and HTTP are both communication protocols. But SOAP is messaging protocol concerned with packaging of messages in XML protocol and transfer then using HTTP . HTTP is used solely used to transfer information over the internet. You can get much more information over internet.How can you explain the SOAP communication model? ›
SOAP (Simple Object Access Protocol) is a message protocol that enables the distributed elements of an application to communicate. SOAP can be carried over a variety of standard protocols, including the web-related Hypertext Transfer Protocol (HTTP).Which three are parts of a SOAP message? ›
A SOAP message is an XML document that consists of a SOAP envelope, an optional SOAP header, and a SOAP body.What are the different data types in SOAP? ›
- xsd:base64Binary: Base64-encoded binary data.
- xsd:boolean: Binary data (true [non-zero] or false ).
- xsd:byte: Short data between -128 and 127.
- xsd:double: IEEE double-precision 64-bit floating point data.
- xsd:float: IEEE single-precision 32-bit floating point data.
IMAP - Internet Message Access Protocol - A protocol for e-mail messages on the Internet. IRC - Internet Relay Chat - a protocol used for Internet chat and other communications. POP3 - Post Office protocol Version 3 - a protocol used by e-mail clients to retrieve messages from remote servers.
- Transmission Control Protocol (TCP) – used for data transmission.
- User Datagram Protocol (UDP) – used by programs to send short datagram messages.
- Internet Control Message Protocol (ICMP) – messages used for diagnostic or error-generating purposes.
There are two types of communication protocols, based on their representation of the content being carried: text-based and binary.What is SOAP API in simple terms? ›
SOAP API, or simple object access protocol application programming interface, is a standard messaging protocol that operating systems use to communicate via Hypertext Transfer Protocol (HTTP) and Extensible Markup Language (XML).Is SOAP protocol the same as REST? ›
While SOAP and REST share similarities over the HTTP protocol, SOAP is a more rigid set of messaging patterns than REST. The rules in SOAP are important because we can't achieve any level of standardization without them. REST as an architecture style does not require processing and is naturally more flexible.What is the best advantage of the SOAP protocol? ›
- Language, platform, and transport independent (REST requires use of HTTP)
- Works well in distributed enterprise environments (REST assumes direct point-to-point communication)
SOAP is an application layer protocol that relies on other application layer protocols (most commonly HTTP) to transport it. (The application layers are 5-7 in the OSI model, with SOAP usually considered part of layer 7.)Can SOAP work without HTTP? ›
Using an underlying transport protocol other than HTTP: SOAP is independent of an underlying transport protocol, so you don't have to use HTTP. Instead, you could use SMTP (Simple Mail Transfer Protocol) or JMS (Java Messaging Service) or another transport protocol, depending on your application.Is SOAP a TCP or UDP? ›
SOAP is a protocol specification for exchanging structured information in the implementation of Web Services. It uses XML for the message format. It is independent of the transport protocol (could be HTTP, FTP, TCP, UDP, or named pipes). SOAP based services strictly define the format of messages passed back and forth.Does SOAP use TCP or UDP? ›
SOAP supports a variety of transfer protocols, both high- and low-level ones. For instance, SOAP allows for messaging via TCP (Transaction Control Protocol), a low-level data exchange method that works between ports via an IP network.Do people still use SOAP protocol? ›
These days, most public web services provide REST APIs and transfer data in the compact and easy-to-use JSON data interchange format. However, enterprise users still frequently choose SOAP for their web services.
Soap is created by mixing fats and oils with a base. A similar process is used for making detergent which is also created by combining chemical compounds in a mixer. Humans have used soap for millennia. Evidence exists for the production of soap-like materials in ancient Babylon around 2800 BC.How will you make SOAP explain in detail? ›
Soaps are sodium or potassium salts of long chain fatty acids. When triglycerides in fat/oil react with aqueous NaOH or KOH, they are converted into soap and glycerol. This is called alkaline hydrolysis of esters. Since this reaction leads to the formation of soap, it is called the Saponification process.What are the four types of SOAP? ›
- Moisturizing Soap. Moisturizing soap has a moisturizing agent that helps moisturize your hands as you wash them. ...
- Antibacterial Soap. Antibacterial soap has become increasingly popular because it kills all the bacteria on your hands if adequately used. ...
- Natural Soap. ...
- Chemical-Free Soap.
A SOAP message is encoded as an XML document, consisting of an <Envelope> element, which contains an optional <Header> element, and a mandatory <Body> element. The <Fault> element, contained in <Body> , is used for reporting errors.How many phases are there of SOAP? ›
-The view has recently been expressed that soap exists in only four solid phases,6 known as a, B, 5 and co, and that only three of these, namely ,B, 5 and w, are encountered incommercial soaps.What are the 5 basic data types? ›
- Double or Real.
The content of a SOAP message is XML data, whereas a JSON message contains JSON data. JSON and XML are different encoding mechanisms for describing structured data. JSON tends to be a more efficient encoding mechanism, so a typical JSON message will be smaller than the equivalent XML message.What is protocol with example? ›
Protocols: It is a set of rules that need to be followed by the communicating parties in order to have successful and reliable data communication. For example - Ethernet and HTTP.What are the 4 types of protocol? ›
Transmission Control Protocol (TCP) Internet Protocol (IP) User Datagram Protocol (UDP) Post office Protocol (POP)What is a protocol and give three examples? ›
Protocols exist for several different applications. Examples include wired networking (e.g., Ethernet), wireless networking (e.g., 802.11ac), and Internet communication (e.g., IP). The Internet protocol suite, which is used for transmitting data over the Internet, contains dozens of protocols.
- HTTP – One of the most familiar protocols, hyper text transfer protocol (HTTP) is often referred to as the protocol of the internet. ...
- TCP – Transmission Control Protocol (TCP) separates data into packets that can be shared over a network.
The most important protocols for data transmission across the Internet are TCP (Transmission Control Protocol) and IP (Internet Protocol).Why is protocol important? ›
Essentially, it allows connected devices to communicate with each other, regardless of any differences in their internal processes, structure or design. Network protocols are the reason you can easily communicate with people all over the world, and thus play a critical role in modern digital communications.What are the main functions of protocols? ›
- Connection Establishment/Release. A data transfer can be a communication-oriented transfer or connectionless transfer. ...
- Encapsulation. ...
- Segmentation and Reassembly. ...
- Data Transfer Management. ...
- Multiplexing/Demultiplexing. ...
- Addressing. ...
- Ordered Delivery. ...
- Error Control.
This layer uses following protocols: HTTP, SMTP, DHCP, FTP, Telnet, SNMP and SMPP.What is SOAP vs REST API example? ›
SOAP is a protocol, whereas REST is an architectural style
For example, a SOAP API that exposes functionality to create a user might include a function called "CreateUser" that would be specified in the SOAP body. A REST API would instead expose a URL /users, and a POST request towards that URL would create a user.
REST and SOAP are two of the oldest and most popular application protocols in use today, and are used in a huge chunk of public APIs. It is important to understand the differences between REST and SOAP, what the pros and cons are, and how each can benefit your organization's goals.Is SOAP a REST or HTTP? ›
While SOAP and REST share similarities over the HTTP protocol, SOAP is a more rigid set of messaging patterns than REST. The rules in SOAP are important because we can't achieve any level of standardization without them. REST as an architecture style does not require processing and is naturally more flexible.Why SOAP is used instead of REST? ›
SOAP provides the following advantages when compared to REST: Language, platform, and transport independent (REST requires use of HTTP) Works well in distributed enterprise environments (REST assumes direct point-to-point communication) Standardized.What are the different HTTP methods in SOAP? ›
The most-commonly-used HTTP methods are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively. There are a number of other methods too, however they are utilized less frequently.
SOAP or Simple Objects Access Protocol is a web communication protocol designed for Microsoft back in 1998. Today, it's mostly used to expose web services and transmit data over HTTP/HTTPS.What is SOAP vs REST for dummies? ›
SOAP is a protocol whereas REST is an architectural pattern. SOAP uses service interfaces to expose its functionality to client applications while REST uses Uniform Service locators to access to the components on the hardware device. SOAP needs more bandwidth for its usage whereas REST doesn't need much bandwidth.Can SOAP run on HTTPS? ›
SOAP may also be used over HTTPS (which is the same protocol as HTTP at the application level, but uses an encrypted transport protocol underneath) with either simple or mutual authentication; this is the advocated WS-I method to provide web service security as stated in the WS-I Basic Profile 1.1.Is SOAP stateful or stateless? ›
SOAP is by default stateless, but it is possible to make this API stateful. It is stateful, i.e. no server-side sessions occur. It is data-driven, meaning that data is available as resources. It has WS-security (Enterprise-level security) with SSL support.