{"id":880,"date":"2010-06-08T18:12:11","date_gmt":"2010-06-08T12:42:11","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=880"},"modified":"2017-03-31T17:16:48","modified_gmt":"2017-03-31T11:46:48","slug":"working-with-soap-calls","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/working-with-soap-calls\/","title":{"rendered":"Working With Soap Calls"},"content":{"rendered":"<p>Hey,<\/p>\n<p>SOAP is one of the popular ways of working with web-services another being <a href=\"http:\/\/www.tothenew.com\/blog\/working-with-rest-call\/\">REST (another of my blog)<\/a>), while working with any of the SOAP based API, you will get a WSDL (web services description\/definition language) describing what all methods are supported by the web service. Its a rather complicated XML document.<\/p>\n<p>A few days back I was working on consuming SOAP based web services. I could not use Groovy WS as the soap calls I needed to make were little complicated, So I used the old httpclient libraries to make the calls. Here is a very simple snippet of the code I was using.<\/p>\n<pre lang=\"groovy\">import org.apache.commons.httpclient.*\r\nimport org.apache.commons.httpclient.methods.*\r\nclass SoapcallController {\r\n\r\n    def index = {\r\n    def url = \"https:\/\/www.paymentsample.biz\/Gateway.asmx\"\r\n    def payload ='\r\n<!--?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?-->\r\n\r\n\r\n\r\nACHACH\r\n'\r\ndef method = new PostMethod(url)\r\n    def client = new HttpClient()\r\n\r\n    payload = payload.trim()\r\n    method.addRequestHeader(\"Content-Type\",\"text\/xml\")\r\n    method.addRequestHeader(\"Accept\",\"text\/xml,application\/xml;q=0.9\")\r\n    method.setRequestEntity(new StringRequestEntity(payload))\r\n    def statusCode = client.executeMethod(method)\r\n    println \"STATUS CODE : ${statusCode}\"\r\n    def resultsString = method.getResponseBodyAsString()\r\n    method.releaseConnection()\r\n    \/\/println new XmlSlurper().parseText(resultsString).toString()\r\n    println resultsString\r\n    }\r\n}<\/pre>\n<p>In this code we are hitting the &#8220;url&#8221; with &#8220;payload&#8221; and getting the response back in the resultsString which itself will be an XML. The payload will change depending upon the WSDL provided.<\/p>\n<p>To generate the payload XML using your own WSDL you can use http:\/\/www.soapclient.com\/soaptest.html. Its a rather nice tool to use and play before using the web service in your application.<\/p>\n<p>And of course rather than working with XML it is always better to work with objects and method calls,search for wsdl2java or better still Axis2 on google for generating classes from wsdl. I will put a <a href=\"http:\/\/www.tothenew.com\/blog\/generating-stubs-for-soap-calls-using-intellijidea\/\">blog<\/a> on generating classes from WSDL using axis2 api in intelliJ IDEA shortly. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, SOAP is one of the popular ways of working with web-services another being REST (another of my blog)), while working with any of the SOAP based API, you will get a WSDL (web services description\/definition language) describing what all methods are supported by the web service. Its a rather complicated XML document. A few [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[7,1],"tags":[4840,9,257],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/880"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=880"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/880\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}