{"id":58380,"date":"2016-07-18T13:00:07","date_gmt":"2016-07-18T10:00:07","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=58380"},"modified":"2016-07-16T15:59:28","modified_gmt":"2016-07-16T12:59:28","slug":"writing-consuming-soap-webservice-spring","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html","title":{"rendered":"Writing and Consuming SOAP Webservice with Spring"},"content":{"rendered":"<p>In the era of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\" target=\"_blank\">RESTful<\/a> Web Services, I got a chance to consume <a href=\"https:\/\/en.wikipedia.org\/wiki\/SOAP\" target=\"_blank\">SOAP<\/a> Web Service. To do the same I chosen <a href=\"https:\/\/projects.spring.io\/spring-framework\/\" target=\"_blank\">Spring<\/a>, reason being we are already using Spring as backend framework in our project and secondly it provides an intuitive way to interact service(s) with well-defined boundaries to promote reusability and portability through <a href=\"http:\/\/docs.spring.io\/spring-ws\/site\/apidocs\/org\/springframework\/ws\/client\/core\/WebServiceTemplate.html\" target=\"_blank\">WebServiceTemplate<\/a>.<\/p>\n<p>Assuming you already know about SOAP Web Services, let\u2019s start creating <strong>hello-world<\/strong> soap service running on port <strong>9999<\/strong> and client to consume the same, following below steps:<\/p>\n<p><strong>Step 1<\/strong>: Go to <a href=\"http:\/\/start.spring.io\/\" target=\"_blank\">start.spring.io <\/a>and create a new project <strong>soap-server<\/strong> adding the Web starters, based on the following image:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-server.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-58421\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-server.png\" alt=\"soap-server\" width=\"648\" height=\"322\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-server.png 648w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-server-300x149.png 300w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><\/a><\/p>\n<p><strong>Step 2:<\/strong> Edit <strong>SoapServerApplication.java<\/strong> to publish the <strong>hello-world<\/strong> service at Endpoint \u2013 <strong><a href=\"http:\/\/localhost:9999\/service\/hello-world\" rel=\"nofollow\">http:\/\/localhost:9999\/service\/hello-world<\/a><\/strong>, as follows:<\/p>\n<pre class=\"brush:java\">package com.arpit.soap.server.main;\r\n\r\nimport javax.xml.ws.Endpoint;\r\n\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.boot.CommandLineRunner;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\n\r\nimport com.arpit.soap.server.service.impl.HelloWorldServiceImpl;\r\n\r\n@SpringBootApplication\r\npublic class SoapServerApplication implements CommandLineRunner {\r\n\r\n\t@Value(\"${service.port}\")\r\n\tprivate String servicePort;\r\n\r\n\t@Override\r\n\tpublic void run(String... args) throws Exception {\r\n\t\tEndpoint.publish(\"http:\/\/localhost:\" + servicePort\r\n\t\t\t\t+ \"\/service\/hello-world\", new HelloWorldServiceImpl());\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSpringApplication.run(SoapServerApplication.class, args);\r\n\t}\r\n}<\/pre>\n<p><strong>Step 3:<\/strong> Edit <strong>application.properties<\/strong> to specify the application name, port and port number of <strong>hello-world<\/strong> service, as follows:<\/p>\n<pre class=\"brush:java\">server.port=9000\r\nspring.application.name=soap-server\r\n\r\n## Soap Service Port\r\nservice.port=9999<\/pre>\n<p><strong>Step 4:<\/strong> Create additional packages as <strong>com.arpit.soap.server.service<\/strong> and <strong>com.arpit.soap.server.service.impl<\/strong> to define the Web Service and it\u2019s implementation, as follows:<\/p>\n<p><strong>HelloWorldService.java<\/strong><\/p>\n<pre class=\"brush:java\">package com.arpit.soap.server.service;\r\n\r\nimport javax.jws.WebMethod;\r\nimport javax.jws.WebParam;\r\nimport javax.jws.WebService;\r\n\r\nimport com.arpit.soap.server.model.ApplicationCredentials;\r\n\r\n@WebService\r\npublic interface HelloWorldService {\r\n\r\n\t@WebMethod(operationName = \"helloWorld\", action = \"https:\/\/aggarwalarpit.wordpress.com\/hello-world\/helloWorld\")\r\n\tString helloWorld(final String name,\r\n\t\t\t@WebParam(header = true) final ApplicationCredentials credential);\r\n\r\n}<\/pre>\n<p><strong>@WebService<\/strong> specified above marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface.<\/p>\n<p><strong>@WebMethod<\/strong> specified above marks a Java method as a Web Service operation.<\/p>\n<p><strong>@WebParam<\/strong> specified above customize the mapping of an individual parameter to a Web Service message part and XML element.<\/p>\n<p><strong>HelloWorldServiceImpl.java<\/strong><\/p>\n<pre class=\"brush:java\">package com.arpit.soap.server.service.impl;\r\n\r\nimport javax.jws.WebService;\r\n\r\nimport com.arpit.soap.server.model.ApplicationCredentials;\r\nimport com.arpit.soap.server.service.HelloWorldService;\r\n\r\n@WebService(endpointInterface = \"com.arpit.soap.server.service.HelloWorldService\")\r\npublic class HelloWorldServiceImpl implements HelloWorldService {\r\n\r\n\t@Override\r\n\tpublic String helloWorld(final String name,\r\n\t\t\tfinal ApplicationCredentials credential) {\r\n\t\treturn \"Hello World from \" + name;\r\n\t}\r\n}<\/pre>\n<p><strong>Step 5:<\/strong> Move to <strong>soap-server<\/strong> directory and run command: <strong>mvn spring-boot:run<\/strong>. Once running, open <strong><a href=\"http:\/\/localhost:9999\/service\/hello-world?wsdl\" rel=\"nofollow\">http:\/\/localhost:9999\/service\/hello-world?wsdl<\/a><\/strong> to view the WSDL for the <strong>hello-world<\/strong> service.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Next, we will create <strong>soap-client<\/strong> which will consume our newly created <strong>hello-world<\/strong> service.<\/p>\n<p><strong>Step 6:<\/strong> Go to <a href=\"http:\/\/start.spring.io\/\" target=\"_blank\">start.spring.io<\/a> and create a new project <strong>soap-client<\/strong> adding the Web, Web Services starters, based on the following image:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-client.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-58422\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-client.png\" alt=\"soap-client\" width=\"648\" height=\"323\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-client.png 648w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/soap-client-300x150.png 300w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><\/a><\/p>\n<p><strong>Step 7:<\/strong> Edit <strong>SoapClientApplication.java<\/strong> to create a request to <strong>hello-world<\/strong> web service, sending the same to <strong>soap-server<\/strong> along with header and get the response from it, as follows:<\/p>\n<pre class=\"brush:java\">package com.arpit.soap.client.main;\r\n\r\nimport java.io.IOException;\r\nimport java.io.StringWriter;\r\n\r\nimport javax.xml.bind.JAXBElement;\r\nimport javax.xml.transform.Transformer;\r\nimport javax.xml.transform.TransformerException;\r\nimport javax.xml.transform.TransformerFactory;\r\nimport javax.xml.transform.stream.StreamResult;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Qualifier;\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.boot.CommandLineRunner;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\nimport org.springframework.context.annotation.ComponentScan;\r\nimport org.springframework.ws.WebServiceMessage;\r\nimport org.springframework.ws.client.core.WebServiceMessageCallback;\r\nimport org.springframework.ws.client.core.WebServiceTemplate;\r\nimport org.springframework.ws.soap.SoapMessage;\r\nimport org.springframework.xml.transform.StringSource;\r\n\r\nimport com.arpit.soap.server.service.ApplicationCredentials;\r\nimport com.arpit.soap.server.service.HelloWorld;\r\nimport com.arpit.soap.server.service.HelloWorldResponse;\r\nimport com.arpit.soap.server.service.ObjectFactory;\r\n\r\n@SpringBootApplication\r\n@ComponentScan(\"com.arpit.soap.client.config\")\r\npublic class SoapClientApplication implements CommandLineRunner {\r\n\r\n\t@Autowired\r\n\t@Qualifier(\"webServiceTemplate\")\r\n\tprivate WebServiceTemplate webServiceTemplate;\r\n\r\n\t@Value(\"#{'${service.soap.action}'}\")\r\n\tprivate String serviceSoapAction;\r\n\r\n\t@Value(\"#{'${service.user.id}'}\")\r\n\tprivate String serviceUserId;\r\n\r\n\t@Value(\"#{'${service.user.password}'}\")\r\n\tprivate String serviceUserPassword;\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSpringApplication.run(SoapClientApplication.class, args);\r\n\t\tSystem.exit(0);\r\n\t}\r\n\r\n\tpublic void run(String... args) throws Exception {\r\n\t\tfinal HelloWorld helloWorld = createHelloWorldRequest();\r\n\t\t@SuppressWarnings(\"unchecked\")\r\n\t\tfinal JAXBElement&lt;HelloWorldResponse&gt; jaxbElement = (JAXBElement&lt;HelloWorldResponse&gt;) sendAndRecieve(helloWorld);\r\n\t\tfinal HelloWorldResponse helloWorldResponse = jaxbElement.getValue();\r\n\t\tSystem.out.println(helloWorldResponse.getReturn());\r\n\t}\r\n\r\n\tprivate Object sendAndRecieve(HelloWorld seatMapRequestType) {\r\n\t\treturn webServiceTemplate.marshalSendAndReceive(seatMapRequestType,\r\n\t\t\t\tnew WebServiceMessageCallback() {\r\n\t\t\t\t\tpublic void doWithMessage(WebServiceMessage message)\r\n\t\t\t\t\t\t\tthrows IOException, TransformerException {\r\n\t\t\t\t\t\tSoapMessage soapMessage = (SoapMessage) message;\r\n\t\t\t\t\t\tsoapMessage.setSoapAction(serviceSoapAction);\r\n\t\t\t\t\t\torg.springframework.ws.soap.SoapHeader soapheader = soapMessage\r\n\t\t\t\t\t\t\t\t.getSoapHeader();\r\n\t\t\t\t\t\tfinal StringWriter out = new StringWriter();\r\n\t\t\t\t\t\twebServiceTemplate.getMarshaller().marshal(\r\n\t\t\t\t\t\t\t\tgetHeader(serviceUserId, serviceUserPassword),\r\n\t\t\t\t\t\t\t\tnew StreamResult(out));\r\n\t\t\t\t\t\tTransformer transformer = TransformerFactory\r\n\t\t\t\t\t\t\t\t.newInstance().newTransformer();\r\n\t\t\t\t\t\ttransformer.transform(new StringSource(out.toString()),\r\n\t\t\t\t\t\t\t\tsoapheader.getResult());\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\t}\r\n\r\n\tprivate Object getHeader(final String userId, final String password) {\r\n\t\tfinal https.aggarwalarpit_wordpress.ObjectFactory headerObjectFactory = new https.aggarwalarpit_wordpress.ObjectFactory();\r\n\t\tfinal ApplicationCredentials applicationCredentials = new ApplicationCredentials();\r\n\t\tapplicationCredentials.setUserId(userId);\r\n\t\tapplicationCredentials.setPassword(password);\r\n\t\tfinal JAXBElement&lt;ApplicationCredentials&gt; header = headerObjectFactory\r\n\t\t\t\t.createApplicationCredentials(applicationCredentials);\r\n\t\treturn header;\r\n\t}\r\n\r\n\tprivate HelloWorld createHelloWorldRequest() {\r\n\t\tfinal ObjectFactory objectFactory = new ObjectFactory();\r\n\t\tfinal HelloWorld helloWorld = objectFactory.createHelloWorld();\r\n\t\thelloWorld.setArg0(\"Arpit\");\r\n\t\treturn helloWorld;\r\n\t}\r\n\r\n}<\/pre>\n<p><strong>Step 8:<\/strong> Next, create additional package <strong>com.arpit.soap.client.config<\/strong> to configure <strong>WebServiceTemplate<\/strong>, as follows:<\/p>\n<p><strong>ApplicationConfig.java<\/strong><\/p>\n<pre class=\"brush:java\">package com.arpit.soap.client.config;\r\n\r\nimport org.springframework.beans.factory.annotation.Value;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.context.support.PropertySourcesPlaceholderConfigurer;\r\nimport org.springframework.oxm.jaxb.Jaxb2Marshaller;\r\nimport org.springframework.web.servlet.config.annotation.EnableWebMvc;\r\nimport org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;\r\nimport org.springframework.ws.client.core.WebServiceTemplate;\r\nimport org.springframework.ws.soap.saaj.SaajSoapMessageFactory;\r\nimport org.springframework.ws.transport.http.HttpComponentsMessageSender;\r\n\r\n@Configuration\r\n@EnableWebMvc\r\npublic class ApplicationConfig extends WebMvcConfigurerAdapter {\r\n\r\n\t@Value(\"#{'${service.endpoint}'}\")\r\n\tprivate String serviceEndpoint;\r\n\r\n\t@Value(\"#{'${marshaller.packages.to.scan}'}\")\r\n\tprivate String marshallerPackagesToScan;\r\n\r\n\t@Value(\"#{'${unmarshaller.packages.to.scan}'}\")\r\n\tprivate String unmarshallerPackagesToScan;\r\n\r\n\t@Bean\r\n\tpublic static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {\r\n\t\treturn new PropertySourcesPlaceholderConfigurer();\r\n\t}\r\n\r\n\t@Bean\r\n\tpublic SaajSoapMessageFactory messageFactory() {\r\n\t\tSaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();\r\n\t\tmessageFactory.afterPropertiesSet();\r\n\t\treturn messageFactory;\r\n\t}\r\n\r\n\t@Bean\r\n\tpublic Jaxb2Marshaller marshaller() {\r\n\t\tJaxb2Marshaller marshaller = new Jaxb2Marshaller();\r\n\t\tmarshaller.setPackagesToScan(marshallerPackagesToScan.split(\",\"));\r\n\t\treturn marshaller;\r\n\t}\r\n\r\n\t@Bean\r\n\tpublic Jaxb2Marshaller unmarshaller() {\r\n\t\tJaxb2Marshaller unmarshaller = new Jaxb2Marshaller();\r\n\t\tunmarshaller.setPackagesToScan(unmarshallerPackagesToScan.split(\",\"));\r\n\t\treturn unmarshaller;\r\n\t}\r\n\r\n\t@Bean\r\n\tpublic WebServiceTemplate webServiceTemplate() {\r\n\t\tWebServiceTemplate webServiceTemplate = new WebServiceTemplate(\r\n\t\t\t\tmessageFactory());\r\n\t\twebServiceTemplate.setMarshaller(marshaller());\r\n\t\twebServiceTemplate.setUnmarshaller(unmarshaller());\r\n\t\twebServiceTemplate.setMessageSender(messageSender());\r\n\t\twebServiceTemplate.setDefaultUri(serviceEndpoint);\r\n\t\treturn webServiceTemplate;\r\n\t}\r\n\r\n\t@Bean\r\n\tpublic HttpComponentsMessageSender messageSender() {\r\n\t\tHttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();\r\n\t\treturn httpComponentsMessageSender;\r\n\t}\r\n}<\/pre>\n<p><strong>Step 9:<\/strong> Edit <strong>application.properties<\/strong> to specify the application name, port and <strong>hello-world<\/strong> soap web service configurations, as follows:<\/p>\n<pre class=\"brush:java\">server.port=9000\r\nspring.application.name=soap-client\r\n\r\n## Soap Service Configuration\r\n\r\nservice.endpoint=http:\/\/localhost:9999\/service\/hello-world\r\nservice.soap.action=https:\/\/aggarwalarpit.wordpress.com\/hello-world\/helloWorld\r\nservice.user.id=arpit\r\nservice.user.password=arpit\r\nmarshaller.packages.to.scan=com.arpit.soap.server.service\r\nunmarshaller.packages.to.scan=com.arpit.soap.server.service<\/pre>\n<p><strong>service.endpoint<\/strong> specified above is the URL provided to the service user to invoke the services exposed by the service provider.<\/p>\n<p><strong>service.soap.action<\/strong> specifies which process or program that need to be called when a request is sent by the service requester and also defines the relative path of the process\/program.<\/p>\n<p><strong>marshaller.packages.to.scan<\/strong> specifies the packages to scan at time of marshalling before sending the request to the server.<\/p>\n<p><strong>unmarshaller.packages.to.scan<\/strong> specifies the packages to scan at time of unmarshalling after receiving the request from the server.<\/p>\n<p>Now, we will generate Java Objects from WSDL using <strong>wsimport<\/strong> and copy it to the <strong>soap-client<\/strong> project executing below command on the terminal:<\/p>\n<pre class=\"brush:java\">wsimport -keep -verbose http:\/\/localhost:9999\/service\/hello-world?wsdl<\/pre>\n<p><strong>Step 10:<\/strong> Move to <strong>soap-client<\/strong> directory and run command: <strong>mvn spring-boot:run<\/strong>. Once command finishes we will see <strong>\u201cHello World from Arpit\u201d<\/strong> as response from <strong>hello-world<\/strong> soap service on console.<\/p>\n<p>While running if you are getting error as \u2013 <strong>Unable to marshal type \u201ccom.arpit.soap.server.service.HelloWorld\u201d as an element because it is missing an @XmlRootElement annotation<\/strong>\u00a0then add @XmlRootElement(name = \u201chelloWorld\u201d, namespace = \u201c<a href=\"http:\/\/service.server.soap.arpit.com\/\" rel=\"nofollow\">http:\/\/service.server.soap.arpit.com\/<\/a> \u201c) to the <strong>com.arpit.soap.server.service.HelloWorld<\/strong>, where namespace should be matched from <strong>xmlns:ser<\/strong> defined in soap envelope, as below:<\/p>\n<pre class=\"brush:java\">&lt;soapenv:Envelope xmlns:soapenv=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\" xmlns:ser=\"http:\/\/service.server.soap.arpit.com\/\"&gt;\r\n   &lt;soapenv:Header&gt;\r\n      &lt;ser:arg1&gt;\r\n         &lt;userId&gt;arpit&lt;\/userId&gt;\r\n         &lt;password&gt;arpit&lt;\/password&gt;\r\n      &lt;\/ser:arg1&gt;\r\n   &lt;\/soapenv:Header&gt;\r\n   &lt;soapenv:Body&gt;\r\n      &lt;ser:helloWorld&gt;\r\n         &lt;!--Optional:--&gt;\r\n         &lt;arg0&gt;Arpit&lt;\/arg0&gt;\r\n      &lt;\/ser:helloWorld&gt;\r\n   &lt;\/soapenv:Body&gt;\r\n&lt;\/soapenv:Envelope&gt;<\/pre>\n<p>The complete source code is hosted on <a href=\"https:\/\/github.com\/arpitaggarwal\/soap\" target=\"_blank\">github<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/aggarwalarpit.wordpress.com\/2016\/07\/15\/writing-and-consuming-soap-webservice-with-spring\/\">Writing and Consuming SOAP Webservice with Spring<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/join-us\/jcg\/\">JCG partner<\/a> Arpit Aggarwal at the <a href=\"https:\/\/aggarwalarpit.wordpress.com\/\">Arpit Aggarwal<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring as backend framework in our project and secondly it provides an intuitive way to interact service(s) with well-defined boundaries to promote reusability and portability through &hellip;<\/p>\n","protected":false},"author":987,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[604,30],"class_list":["post-58380","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-soap","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Writing and Consuming SOAP Webservice with Spring - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Writing and Consuming SOAP Webservice with Spring - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/arpit.aggarwal.1989\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-18T10:00:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Arpit Aggarwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@aggarwalarpit89\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Arpit Aggarwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html\"},\"author\":{\"name\":\"Arpit Aggarwal\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/3927a00b4d96161bd6325e311a40e98e\"},\"headline\":\"Writing and Consuming SOAP Webservice with Spring\",\"datePublished\":\"2016-07-18T10:00:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html\"},\"wordCount\":592,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"SOAP\",\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html\",\"name\":\"Writing and Consuming SOAP Webservice with Spring - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2016-07-18T10:00:07+00:00\",\"description\":\"In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2016\\\/07\\\/writing-consuming-soap-webservice-spring.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Writing and Consuming SOAP Webservice with Spring\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/3927a00b4d96161bd6325e311a40e98e\",\"name\":\"Arpit Aggarwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g\",\"caption\":\"Arpit Aggarwal\"},\"description\":\"Arpit is a Consultant at Xebia India. He has been designing and building J2EE applications since more than 6 years. He is fond of Object Oriented and lover of Functional programming. You can read more of his writings at aggarwalarpit.wordpress.com\",\"sameAs\":[\"https:\\\/\\\/aggarwalarpit.wordpress.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/arpit.aggarwal.1989\",\"https:\\\/\\\/in.linkedin.com\\\/in\\\/arpitaggarwalxebia\",\"https:\\\/\\\/x.com\\\/aggarwalarpit89\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/arpit-aggarwal\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Writing and Consuming SOAP Webservice with Spring - Java Code Geeks","description":"In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html","og_locale":"en_US","og_type":"article","og_title":"Writing and Consuming SOAP Webservice with Spring - Java Code Geeks","og_description":"In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring","og_url":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/arpit.aggarwal.1989","article_published_time":"2016-07-18T10:00:07+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Arpit Aggarwal","twitter_card":"summary_large_image","twitter_creator":"@aggarwalarpit89","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Arpit Aggarwal","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html"},"author":{"name":"Arpit Aggarwal","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/3927a00b4d96161bd6325e311a40e98e"},"headline":"Writing and Consuming SOAP Webservice with Spring","datePublished":"2016-07-18T10:00:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html"},"wordCount":592,"commentCount":7,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["SOAP","Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html","url":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html","name":"Writing and Consuming SOAP Webservice with Spring - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2016-07-18T10:00:07+00:00","description":"In the era of RESTful Web Services, I got a chance to consume SOAP Web Service. To do the same I chosen Spring, reason being we are already using Spring","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2016\/07\/writing-consuming-soap-webservice-spring.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Writing and Consuming SOAP Webservice with Spring"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/3927a00b4d96161bd6325e311a40e98e","name":"Arpit Aggarwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a0dc71e538e67766feb7c436ea43f02757eeb1f9446613ae680752be7239a3f6?s=96&d=mm&r=g","caption":"Arpit Aggarwal"},"description":"Arpit is a Consultant at Xebia India. He has been designing and building J2EE applications since more than 6 years. He is fond of Object Oriented and lover of Functional programming. You can read more of his writings at aggarwalarpit.wordpress.com","sameAs":["https:\/\/aggarwalarpit.wordpress.com\/","https:\/\/www.facebook.com\/arpit.aggarwal.1989","https:\/\/in.linkedin.com\/in\/arpitaggarwalxebia","https:\/\/x.com\/aggarwalarpit89"],"url":"https:\/\/www.javacodegeeks.com\/author\/arpit-aggarwal"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/58380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/987"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=58380"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/58380\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=58380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=58380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=58380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}