//Karthik Srinivasan

Product Engineer, CTO & a Beer Enthusiast
Experiments, thoughts and scripts documented for posterity.

Quirky Personal Projects

LinkedIn

Email me

Calling SOAP Service in Scala

March, 2015

Scala out of the box has limited capability to call SOAP service neither does libraries such as http-dispatch or spray client. SOAP service in reality is just a xml request/response service and lo and behold, XML is a first class citizen in Scala.

One of the widely used library is ScalaXB which helps in generating case classes given a xsd or wsdl file. Scalaxb is an XML data-binding tool for Scala that supports W3C XML Schema (xsd) and Web Services Description Language (wsdl) as the input file. This is great but it's quite hard to maintain and the code readability goes down the drain as the code is dynamically generated. For example, the following screen shot is what scalaxb generates when either a wsdl or xsd is provided


But what we really need is a trivial way to call a webservice using our existing http clients. Following is one way of doing so. In this below example, i am calling a service that returns back a list of keywords given a list of keywordId's.


In the above script, all that i am doing is constructing the soap request headers manually and performing a POST operation. There are couple of things to be noted: GetKeywordDetailsRequest is a class that has the input parameters and has a function that generates the formatted xml for the soap request