Categories: SOAP

SOAP Encoding

<div dir&equals;"ltr" style&equals;"text-align&colon; left&semi;" trbidi&equals;"on">SOAP includes a built-in set of rules for encoding data types&period;This enables the SOAP message to indicate specific data types&comma; such as integers&comma; floats&comma; doubles&comma; or arrays&period;<&sol;p>&NewLine;<ul>&NewLine;<li>SOAP data types are divided into two broad categories&colon; scalar types and compound types&period; <&sol;li>&NewLine;<li>Scalar types contain exactly one value&comma; such as a last name&comma; price&comma; or product description&period; <&sol;li>&NewLine;<li>Compound types contain multiple values&comma; such as a purchase order or a list of stock quotes&period; <&sol;li>&NewLine;<li>Compound types are further subdivided into arrays and structs&period; <&sol;li>&NewLine;<li>The encoding style for a SOAP message is set via the SOAP-ENV&colon;encodingStyle attribute&period; <&sol;li>&NewLine;<li>To use SOAP 1&period;1 encoding&comma; use the value <a href&equals;"http&colon;&sol;&sol;schemas&period;xmlsoap&period;org&sol;soap&sol;encoding&sol;" target&equals;"&lowbar;blank">http&colon;&sol;&sol;schemas&period;xmlsoap&period;org&sol;soap&sol;encoding&sol;<&sol;a> <&sol;li>&NewLine;<li>To use SOAP 1&period;2 encoding&comma; use the value <a href&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-encoding" target&equals;"&lowbar;blank">http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-encoding<&sol;a> <&sol;li>&NewLine;<li>Latest SOAP specification adopts all the built-in types defined by XML Schema&period; Still SOAP maintains its own convention for defining constructs not standardized by XML Schema&comma; such as arrays and references&period; <&sol;li>&NewLine;<&sol;ul>&NewLine;<div align&equals;'center' id&equals;"ads-id"><&sol;div>&NewLine;<p><b><br &sol;>&NewLine;Scalar Types<&sol;b><br &sol;>&NewLine;For scalar types&comma; SOAP adopts all the built-in simple types specified by the XML Schema specification&period; This includes strings&comma; floats&comma; doubles&comma; and integers&period;<br &sol;>&NewLine;Following table lists the main simple types&comma; excerpted from the XML Schema Part 0&colon; Primer<br &sol;>&NewLine;<a href&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;TR&sol;2000&sol;WD-xmlschema-0-20000407&sol;" target&equals;"&lowbar;blank">http&colon;&sol;&sol;www&period;w3&period;org&sol;TR&sol;2000&sol;WD-xmlschema-0-20000407&sol;<&sol;a><&sol;p>&NewLine;<table border&equals;"1" class&equals;"src" style&equals;"width&colon; 100&percnt;px&semi;">&NewLine;<tbody>&NewLine;<tr>&NewLine;<th align&equals;"center" colspan&equals;"3">Simple Types Built-In to XML Schema <&sol;th>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<th align&equals;"left">Simple Type <&sol;th>&NewLine;<th align&equals;"left">Example&lpar;s&rpar; <&sol;th>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>string <&sol;td>&NewLine;<td>Confirm this is electric <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>boolean <&sol;td>&NewLine;<td>true&comma; false&comma; 1&comma; 0 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>float <&sol;td>&NewLine;<td>-INF&comma; -1E4&comma; -0&comma; 0&comma; 12&period;78E-2&comma; 12&comma; INF&comma; NaN <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>double <&sol;td>&NewLine;<td>-INF&comma; -1E4&comma; -0&comma; 0&comma; 12&period;78E-2&comma; 12&comma; INF&comma; NaN <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>decimal <&sol;td>&NewLine;<td>-1&period;23&comma; 0&comma; 123&period;4&comma; 1000&period;00 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>binary <&sol;td>&NewLine;<td>100010 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>integer <&sol;td>&NewLine;<td>-126789&comma; -1&comma; 0&comma; 1&comma; 126789 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>nonPositiveInteger <&sol;td>&NewLine;<td>-126789&comma; -1&comma; 0 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>negativeInteger <&sol;td>&NewLine;<td>-126789&comma; -1 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>long <&sol;td>&NewLine;<td>-1&comma; 12678967543233 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>int <&sol;td>&NewLine;<td>-1&comma; 126789675 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>short <&sol;td>&NewLine;<td>-1&comma; 12678 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>byte <&sol;td>&NewLine;<td>-1&comma; 126 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>nonNegativeInteger <&sol;td>&NewLine;<td>0&comma; 1&comma; 126789 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>unsignedLong <&sol;td>&NewLine;<td>0&comma; 12678967543233 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>unsignedInt <&sol;td>&NewLine;<td>0&comma; 1267896754 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>unsignedShort <&sol;td>&NewLine;<td>0&comma; 12678 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>unsignedByte <&sol;td>&NewLine;<td>0&comma; 126 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>positiveInteger <&sol;td>&NewLine;<td>1&comma; 126789 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>date <&sol;td>&NewLine;<td>1999-05-31&comma; &&num;8212&semi;05 <&sol;td>&NewLine;<&sol;tr>&NewLine;<tr>&NewLine;<td>time <&sol;td>&NewLine;<td>13&colon;20&colon;00&period;000&comma; 13&colon;20&colon;00&period;000-05&colon;00 <&sol;td>&NewLine;<&sol;tr>&NewLine;<&sol;tbody>&NewLine;<&sol;table>&NewLine;<p>For example&comma; here is a SOAP response with a double data type&colon;<&sol;p>&NewLine;<pre class&equals;"highlight" name&equals;"code">&lt&semi;&quest;xml version&equals;'1&period;0' encoding&equals;'UTF-8'&quest;&gt&semi;&semi;&NewLine;&lt&semi;SOAP-ENV&colon;Envelope&NewLine; xmlns&colon;SOAP-ENV&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-envelope"&NewLine; xmlns&colon;xsi&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema-instance"&NewLine; xmlns&colon;xsd&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema"&gt&semi;&NewLine;&lt&semi;SOAP-ENV&colon;Body&gt&semi;&NewLine; &lt&semi;ns1&colon;getPriceResponse&NewLine; xmlns&colon;ns1&equals;"urn&colon;examples&colon;priceservice"&NewLine; SOAP-ENV&colon;encodingStyle&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-encoding"&gt&semi;&NewLine; &lt&semi;return xsi&colon;type&equals;"xsd&colon;double"&gt&semi;54&period;99&lt&semi;&sol;return&gt&semi;&NewLine; &lt&semi;&sol;ns1&colon;getPriceResponse&gt&semi;&NewLine;&lt&semi;&sol;SOAP-ENV&colon;Body&gt&semi;&NewLine;&lt&semi;&sol;SOAP-ENV&colon;Envelope&gt&semi;&NewLine;<&sol;pre>&NewLine;<p><b><br &sol;>&NewLine;Compound Types<&sol;b><br &sol;>&NewLine;SOAP arrays have a very specific set of rules&comma; which require that you specify both the element type and array size&period; SOAP also supports multidimensional arrays&comma; but not all SOAP implementations support multidimensional functionality&period;<br &sol;>&NewLine;To create an array&comma; you must specify it as an xsi&colon;type of Array&period; The array must also include an arrayType attribute&period; This attribute is required to specify the data type for the contained elements and the dimension&lpar;s&rpar; of the array&period;<br &sol;>&NewLine;For example&comma; the following attribute specifies an array of 10 double values&colon;<&sol;p>&NewLine;<table class&equals;"src" style&equals;"width&colon; 100&percnt;px&semi;">&NewLine;<tbody>&NewLine;<tr>&NewLine;<td>&NewLine;<pre class&equals;"highlight">arrayType&equals;"xsd&colon;double&lbrack;10&rsqb;"&NewLine;<&sol;pre>&NewLine;<&sol;td>&NewLine;<&sol;tr>&NewLine;<&sol;tbody>&NewLine;<&sol;table>&NewLine;<p>In contrast&comma; the following attribute specifies a two-dimensional array of strings&colon; <&sol;p>&NewLine;<table class&equals;"ex" style&equals;"width&colon; 100&percnt;px&semi;">&NewLine;<tbody>&NewLine;<tr>&NewLine;<td>&NewLine;<pre class&equals;"highlight">arrayType&equals;"xsd&colon;string&lbrack;5&comma;5&rsqb;"&NewLine;<&sol;pre>&NewLine;<&sol;td>&NewLine;<&sol;tr>&NewLine;<&sol;tbody>&NewLine;<&sol;table>&NewLine;<p>Here is a sample SOAP response with an array of double values&colon;<&sol;p>&NewLine;<pre class&equals;"highlight" name&equals;"code">&lt&semi;&quest;xml version&equals;'1&period;0' encoding&equals;'UTF-8'&quest;&gt&semi;&NewLine;&lt&semi;SOAP-ENV&colon;Envelope&NewLine; xmlns&colon;SOAP-ENV&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-envelope"&NewLine; xmlns&colon;xsi&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema-instance"&NewLine; xmlns&colon;xsd&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema"&gt&semi;&NewLine;&lt&semi;SOAP-ENV&colon;Body&gt&semi;&NewLine; &lt&semi;ns1&colon;getPriceListResponse&NewLine; xmlns&colon;ns1&equals;"urn&colon;examples&colon;pricelistservice"&NewLine; SOAP-ENV&colon;encodingStyle&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-encoding"&gt&semi;&NewLine; &lt&semi;return&NewLine; xmlns&colon;ns2&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;09&sol;soap-encoding"&NewLine; xsi&colon;type&equals;"ns2&colon;Array" ns2&colon;arrayType&equals;"xsd&colon;double&lbrack;2&rsqb;"&gt&semi;&NewLine; &lt&semi;item xsi&colon;type&equals;"xsd&colon;double"&gt&semi;54&period;99&lt&semi;&sol;item&gt&semi;&NewLine; &lt&semi;item xsi&colon;type&equals;"xsd&colon;double"&gt&semi;19&period;99&lt&semi;&sol;item&gt&semi;&NewLine; &lt&semi;&sol;return&gt&semi;&NewLine; &lt&semi;&sol;ns1&colon;getPriceListResponse&gt&semi;&NewLine;&lt&semi;&sol;SOAP-ENV&colon;Body&gt&semi;&NewLine;&lt&semi;&sol;SOAP-ENV&colon;Envelope&gt&semi;&NewLine;<&sol;pre>&NewLine;<p>Structs contain multiple values&comma; but each element is specified with a unique accessor element&period; For example&comma; consider an item within a product catalog&period; In this case&comma; the struct might contain a product SKU&comma; product name&comma; description&comma; and price&period; Here is how such a struct would be represented in a SOAP message&colon;<&sol;p>&NewLine;<pre class&equals;"highlight" name&equals;"code">&lt&semi;&quest;xml version&equals;'1&period;0' encoding&equals;'UTF-8'&quest;&gt&semi;&NewLine;&lt&semi;SOAP-ENV&colon;Envelope&NewLine; xmlns&colon;SOAP-ENV&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-envelope"&NewLine; xmlns&colon;xsi&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema-instance"&NewLine; xmlns&colon;xsd&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;XMLSchema"&gt&semi;&NewLine;&lt&semi;SOAP-ENV&colon;Body&gt&semi;&NewLine; &lt&semi;ns1&colon;getProductResponse&NewLine; xmlns&colon;ns1&equals;"urn&colon;examples&colon;productservice"&NewLine; SOAP-ENV&colon;encodingStyle&equals;"http&colon;&sol;&sol;www&period;w3&period;org&sol;2001&sol;12&sol;soap-encoding"&gt&semi;&NewLine; &lt&semi;return xmlns&colon;ns2&equals;"urn&colon;examples" xsi&colon;type&equals;"ns2&colon;product"&gt&semi;&NewLine; &lt&semi;name xsi&colon;type&equals;"xsd&colon;string"&gt&semi;Red Hat Linux&lt&semi;&sol;name&gt&semi;&NewLine; &lt&semi;price xsi&colon;type&equals;"xsd&colon;double"&gt&semi;54&period;99&lt&semi;&sol;price&gt&semi;&NewLine; &lt&semi;description xsi&colon;type&equals;"xsd&colon;string"&gt&semi;&NewLine; Red Hat Linux Operating System&NewLine; &lt&semi;&sol;description&gt&semi;&NewLine; &lt&semi;SKU xsi&colon;type&equals;"xsd&colon;string"&gt&semi;A358185&lt&semi;&sol;SKU&gt&semi;&NewLine; &lt&semi;&sol;return&gt&semi;&NewLine; &lt&semi;&sol;ns1&colon;getProductResponse&gt&semi;&NewLine;&lt&semi;&sol;SOAP-ENV&colon;Body&gt&semi;&NewLine;&lt&semi;&sol;SOAP-ENV&colon;Envelope&gt&semi;&NewLine;<&sol;pre>&NewLine;<p><b>NOTE<&sol;b>&colon; Please you take care of proper indentation while you write your SOAP code&period;<&sol;p>&NewLine;<p> Each element in a struct is specified with a unique accessor name&period; For example&comma; the message above includes four accessor elements&colon; name &comma; price &comma; description &comma; and SKU&period; Each element can have its own data type&semi; for example&comma; name is specified as a string &comma; whereas price is specified as a double&period;<&sol;p>&NewLine;<p><i><b>References<&sol;b><&sol;i><br &sol;>&NewLine;1&period; <i><b><a href&equals;"http&colon;&sol;&sol;en&period;wikipedia&period;org&sol;wiki&sol;SOAP" target&equals;"&lowbar;blank">Wikipedia for SOAP<&sol;a><&sol;b><&sol;i><&sol;p>&NewLine;<p>&nbsp&semi; <&sol;p>&NewLine;<div style&equals;"background-color&colon; pink&semi; border-width&colon; thin&semi; text-align&colon; center&semi;"><b>&lt&semi;&lt&semi;<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;05&sol;soap-fault-element&period;html">Previous<&sol;a> &lt&semi;&lt&semi;&nbsp&semi;&nbsp&semi; &vert;&vert; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;01&sol;core-java-baby-step-to-be-best-java-ian&period;html">Index <&sol;a>&vert;&vert; &nbsp&semi; &gt&semi;&gt&semi;<a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;2013&sol;05&sol;soap-transport&period;html">Next<&sol;a> &gt&semi;&gt&semi;<&sol;b><&sol;div>&NewLine;<p>&NewLine;<&sol;div>&NewLine;<div class&equals;"wp-post-navigation"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-pre"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;soap-fault-element&sol;">Previous<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <div class&equals;"wp-post-navigation-next"> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <a href&equals;"https&colon;&sol;&sol;dineshonjava&period;com&sol;soap-transport&sol;">Next<&sol;a> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab; <&sol;div> &NewLine;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;&Tab;<&sol;div>&NewLine;<script type&equals;"text&sol;javascript">&NewLine;jQuery&lpar;document&rpar;&period;ready&lpar;function&lpar;&dollar;&rpar; &lbrace;&NewLine; &dollar;&period;post&lpar;'https&colon;&sol;&sol;dineshonjava&period;com&sol;wp-admin&sol;admin-ajax&period;php'&comma; &lbrace;action&colon; 'mts&lowbar;view&lowbar;count'&comma; id&colon; '441'&rcub;&rpar;&semi;&NewLine;&rcub;&rpar;&semi;&NewLine;<&sol;script>

Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design PatternsĀ using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

4 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

4 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

4 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

4 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

4 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

4 years ago