{"id":2650,"date":"2018-02-13T02:53:38","date_gmt":"2018-02-13T02:53:38","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=2650"},"modified":"2021-02-21T17:17:30","modified_gmt":"2021-02-21T17:17:30","slug":"soap-notes-from-java-brains","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/soap-notes-from-java-brains\/","title":{"rendered":"Notes on SOAP Web Services"},"content":{"rendered":"<p><strong>SOAP(Simple Object Access Protocol)<\/strong> &#8211; SOAP is an XML-based protocol that lets you exchange info over a particular protocol (can be HTTP or SMTP, for example) between applications. It stands for Simple Object Access Protocol and uses XML for its messaging format to relay the information.<\/p>\n<p><strong>WSDL(Web Services Definition Language)<\/strong> &#8211; A WSDL is an XML document that describes a web service. WSDL tells about the functions that you can implement or exposed to the client. For example: add, delete, subtract, and so on. what is the service called, which methods does it offer, what kind of in parameters and return values do these methods have?<\/p>\n<p><strong>XSD(XML Schema Definition)<\/strong> &#8211; describes the static structure of the complex data types being exchanged by those service methods. It describes the types, their fields, any restriction on those fields (like max length or a regex pattern), and so forth.It&#8217;s a description of datatypes and thus static properties of the service &#8211; it&#8217;s about data.<\/p>\n<p><em>XSD definitions are part of WSDL in the <wsdl:types> tag<\/em><\/p>\n<p><strong>UDDI(Universal Description, Discovery, and Integration)<\/strong>&#8211;  It is directly that is used to publish and discover public web services. UDDI is an obsolete failure that is almost never used in practice.UDDI works just like a telephone directory where a business can be registered as per its name, geography and the web services it publishes.UDDI registers the WSDL address URL of a web service. A client of the web service searches and finds the WSDL in the UDDI registry. Once received the WSDL can be invoked by using the URL.<\/p>\n<p>WSDL: When we go to a restaurant we see the Menu Items, those are the WSDL&#8217;s.<br \/>\nProxy Classes: Now after seeing the Menu Items we make up our Mind (Process our mind on what to order): So, basically we make Proxy classes based on WSDL Document.<br \/>\nSOAP: Then when we actually order the food based on the Menu&#8217;s: Meaning we use proxy classes to call upon the service methods which is done using SOAP<\/p>\n<p><strong>SEI(service endpoint interface)<\/strong>: The endpoint is a connection point where HTML files or active server pages are exposed. A web service endpoint is a URL that another program would use to communicate with your program. To see the WSDL, you add WSDL to the web service endpoint URL.<\/p>\n<p><strong>Parts of WSDL<\/strong><br \/>\n<strong>Definitions <\/strong>&#8211; variables &#8211; ex: myVar, x, y, etc.<\/p>\n<p><strong>Types <\/strong>&#8211; data types &#8211; ex: int, double, String, myObjectType<\/p>\n<p><strong>Operations <\/strong>&#8211; methods\/functions &#8211; ex: myMethod(), myFunction(), etc.<\/p>\n<p><strong>Messages <\/strong>&#8211; method\/function input parameters &#038; return types<\/p>\n<p>ex: public myObjectType myMethod(String myVar)<br \/>\n<strong>Porttypes <\/strong>&#8211; classes (i.e. they are a container for operations) &#8211; ex: MyClass{}, etc.<\/p>\n<p><strong>Example of a Endpoint URL<\/strong><\/p>\n<pre>\r\nprotocol:\/\/host:port\/partOfThePath\r\n<\/pre>\n<p>where<\/p>\n<pre>\r\nhost=someIp\r\nport=8080\r\npartOfThePath=\/some\/service\/path\r\n<\/pre>\n<p><em>serviceAEndpoint=http:\/\/host:port\/some\/service\/path?dynamicParam=<\/em><\/p>\n<p><strong>Simple SOAP Request and Response<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n package com.mugil.org;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\nimport javax.jws.WebService;\r\n\r\n@WebService\r\npublic class Products \r\n{\r\n  List&lt;String&gt; arrProducts = new ArrayList&lt;String&gt;();\r\n\t\r\n  public Products()\r\n  {\r\n\tarrProducts.add(&quot;Books&quot;);\r\n\tarrProducts.add(&quot;EReader&quot;);\r\n\tarrProducts.add(&quot;PDF&quot;);\t\r\n  }\r\n  \r\n  public String getProduct(int index)\r\n  {\r\n\treturn arrProducts.get(index);  \r\n  }\r\n}\r\n<\/pre>\n<p><strong>SOAP Request<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;soapenv:Envelope xmlns:soapenv=&quot;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&quot; xmlns:org=&quot;http:\/\/org.mugil.com\/&quot;&gt;\r\n   &lt;soapenv:Header\/&gt;\r\n   &lt;soapenv:Body&gt;\r\n \r\n      &lt;org:getProduct&gt;\r\n         &lt;arg0&gt;0&lt;\/arg0&gt;\r\n      &lt;\/org:getProduct&gt;\r\n   &lt;\/soapenv:Body&gt;\r\n&lt;\/soapenv:Envelope&gt;\r\n<\/pre>\n<p><strong>SOAP Request<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;soap:Envelope xmlns:soap=&quot;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&quot;&gt;\r\n   &lt;soap:Body&gt;\r\n      &lt;ns2:getProductResponse xmlns:ns2=&quot;http:\/\/org.mugil.com\/&quot;&gt;\r\n         &lt;return&gt;Books&lt;\/return&gt;\r\n      &lt;\/ns2:getProductResponse&gt;\r\n   &lt;\/soap:Body&gt;\r\n&lt;\/soap:Envelope&gt;\r\n<\/pre>\n<p><strong>Part of WSDL<\/strong><br \/>\nTypical WSDL document contains the following tags<\/p>\n<ol>\n<li><strong>service<\/strong> &#8211; Contains the port which defines the Endpoint URL, port number<\/li>\n<li><strong>portType<\/strong> &#8211; Contains input and output for an operation.Though there are multiple input and output arguments they would be bundled together as one message<\/li>\n<li><strong>binding<\/strong> &#8211; Defines how the SOAP service could be accessed like over http,https<\/li>\n<li><strong>types<\/strong> &#8211; Type defined as complex type defines the Input and output<\/li>\n<li><strong>message<\/strong> &#8211; Kind of input and output taken as argument, mostly represented as Message<\/li>\n<\/ol>\n<p><strong>Service<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;wsdl:service name=&quot;ProductsService&quot;&gt;\r\n  &lt;wsdl:port binding=&quot;tns:ProductsServiceSoapBinding&quot; name=&quot;ProductsPort&quot;&gt;\r\n   &lt;soap:address location=&quot;http:\/\/localhost:8096\/WebService1\/Products&quot;\/&gt;\r\n  &lt;\/wsdl:port&gt;\r\n  &lt;\/wsdl:service&gt;\r\n<\/pre>\n<p><strong>Porttype<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;wsdl:portType name=&quot;Products&quot;&gt;\r\n   &lt;wsdl:operation name=&quot;getProduct&quot;&gt;\r\n    &lt;wsdl:input message=&quot;tns:getProduct&quot; name=&quot;getProduct&quot;&gt;&lt;\/wsdl:input&gt;\r\n    &lt;wsdl:output message=&quot;tns:getProductResponse&quot; name=&quot;getProductResponse&quot;&gt;&lt;\/wsdl:output&gt;\r\n   &lt;\/wsdl:operation&gt;\r\n  &lt;\/wsdl:portType&gt;\r\n<\/pre>\n<p><strong>Binding<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;wsdl:binding name=&quot;ProductsServiceSoapBinding&quot; type=&quot;tns:Products&quot;&gt;\r\n      &lt;soap:binding style=&quot;document&quot; transport=&quot;http:\/\/schemas.xmlsoap.org\/soap\/http&quot; \/&gt;\r\n      &lt;wsdl:operation name=&quot;getProduct&quot;&gt;\r\n         &lt;soap:operation soapAction=&quot;&quot; style=&quot;document&quot; \/&gt;\r\n         &lt;wsdl:input name=&quot;getProduct&quot;&gt;\r\n            &lt;soap:body use=&quot;literal&quot; \/&gt;\r\n         &lt;\/wsdl:input&gt;\r\n         &lt;wsdl:output name=&quot;getProductResponse&quot;&gt;\r\n            &lt;soap:body use=&quot;literal&quot; \/&gt;\r\n         &lt;\/wsdl:output&gt;\r\n      &lt;\/wsdl:operation&gt;\r\n   &lt;\/wsdl:binding&gt;\r\n<\/pre>\n<p><strong>Types<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;wsdl:types&gt;\r\n      &lt;xs:schema xmlns:xs=&quot;http:\/\/www.w3.org\/2001\/XMLSchema&quot; elementFormDefault=&quot;unqualified&quot; targetNamespace=&quot;http:\/\/org.mugil.com\/&quot; version=&quot;1.0&quot;&gt;\r\n         &lt;xs:element name=&quot;getProduct&quot; type=&quot;tns:getProduct&quot; \/&gt;\r\n         &lt;xs:element name=&quot;getProductResponse&quot; type=&quot;tns:getProductResponse&quot; \/&gt;\r\n         &lt;xs:complexType name=&quot;getProduct&quot;&gt;\r\n            &lt;xs:sequence&gt;\r\n               &lt;xs:element name=&quot;arg0&quot; type=&quot;xs:int&quot; \/&gt;\r\n            &lt;\/xs:sequence&gt;\r\n         &lt;\/xs:complexType&gt;\r\n         &lt;xs:complexType name=&quot;getProductResponse&quot;&gt;\r\n            &lt;xs:sequence&gt;\r\n               &lt;xs:element minOccurs=&quot;0&quot; name=&quot;return&quot; type=&quot;xs:string&quot; \/&gt;\r\n            &lt;\/xs:sequence&gt;\r\n         &lt;\/xs:complexType&gt;\r\n      &lt;\/xs:schema&gt;\r\n<\/pre>\n<p><strong>Message<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;wsdl:message name=&quot;getProduct&quot;&gt;\r\n      &lt;wsdl:part element=&quot;tns:getProduct&quot; name=&quot;parameters&quot; \/&gt;\r\n   &lt;\/wsdl:message&gt;\r\n   &lt;wsdl:message name=&quot;getProductResponse&quot;&gt;\r\n      &lt;wsdl:part element=&quot;tns:getProductResponse&quot; name=&quot;parameters&quot; \/&gt;\r\n   &lt;\/wsdl:message&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2018\/02\/SOAP-WSDL-Eg.png\" alt=\"\" height=\"459\" width=\"1017\"\/><\/p>\n<pre>\r\nService(Class name with @WebService Annotation) \r\n                | \r\nPort(has Binding which defines portType)\r\n                | \r\n    PortType(defines Operations)\r\n                | \r\nOperations(defines input and output Type)<\/strong>\r\n<\/pre>\n<p><strong>Annotations for WebService<\/strong><\/p>\n<pre>\r\n@Webservice(name=\"MartCatalogue\", portName=\"MartCataloguePort\", serviceName=\"ProductsService\", targetNamespace=\"MartProducts.com\")\r\n.\r\n.\r\n@WebMethod(action=\"fetch_products\", operationName=\"fetchProducts\")\r\n.\r\n<\/pre>\n<p><strong>name<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;wsdl:portType name=&quot;MartCatalogue&quot;&gt;\r\n.\r\n.\r\n<\/pre>\n<p><strong>portName and serviceName<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\nwsdl:port binding=&quot;tns:productServiceSoapBinding&quot; name=&quot;productPort&quot;&gt;\r\n  &lt;soap:address location=&quot;http:\/\/localhost:8096\/WebService1\/productService&quot;\/&gt;\r\n&lt;\/wsdl:port&gt;\r\n.\r\n.\r\n<\/pre>\n<p><strong>targetNamespace<\/strong><br \/>\nDefines unique set of operations under namespace.Defaults to package name in java in reverse order<br \/>\ntargetNamespace=&#8221;MartProducts.com&#8221;<\/p>\n<p><strong>targetNamespace<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;wsdl:operation name=&quot;fetchProducts&quot;&gt;\r\n.\r\n.\r\n<\/pre>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n &lt;wsdl:operation name=&quot;fetchProducts&quot;&gt;\r\n      &lt;soap:operation soapAction=&quot;fetch_products&quot; style=&quot;document&quot; \/&gt;\r\n  .\r\n  .\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SOAP(Simple Object Access Protocol) &#8211; SOAP is an XML-based protocol that lets you exchange info over a particular protocol (can be HTTP or SMTP, for example) between applications. It stands for Simple Object Access Protocol and uses XML for its messaging format to relay the information. WSDL(Web Services Definition Language) &#8211; A WSDL is an&hellip; <a href=\"https:\/\/codethataint.com\/blog\/soap-notes-from-java-brains\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220],"tags":[],"class_list":["post-2650","post","type-post","status-publish","format-standard","hentry","category-soap"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=2650"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2650\/revisions"}],"predecessor-version":[{"id":4169,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/2650\/revisions\/4169"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=2650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=2650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=2650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}