web-servicesscalasoapwsdlscalaxb

Errors with using Scalaxb for code generation


I had to fiddle with a WSDL document for one of the implementations and I came across Scalaxb! I'm now trying to generate some scala classes from the WSDL file that I have and as expected I'm hitting into some issues:

Here is a snippet of the WSDL file:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:tns="http://www.myservice.com/MyServices/2012/06/18/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
 xmlns:s="http://www.w3.org/2001/XMLSchema"
 name="MyServices"
 targetNamespace="http://www.myservice.com/MyServices/2012/06/18/">
<wsdl:types>
 <s:schema elementFormDefault="qualified" targetNamespace="http://www.myservice.com/MyServices/2012/06/18/">
  <s:complexType name="UserCredentials">
   <s:sequence>
    <s:element name="UserName" type="s:string" />
    <s:element name="Password" type="s:string" />
   </s:sequence>
  </s:complexType>
  <s:element name="UserCredentials" type="tns:UserCredentials" />
  <s:complexType name="AnotherComplexType" >
   <s:sequence>
    <s:element name="Index" type="s:int" />
    <s:element name="Name" type="s:string" />
    <s:element name="Status" type="s:boolean" />
   </s:sequence>
  </s:complexType>
  ....

Assume that the rest of the WSDL file is completely fine, when I tried to compile the project, I hit the following error:

[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1542: not found: value userCredentials
[error]             scalaxb.toXML(userCredentials, Some("http://www.myservice.com/MyServices/2012/06/18/"), "UserCredentials", defaultScope), defaultScope, baseAddress, "POST", Some(new java.net.URI("http://1.1.1.1/cgi-bin/cgi.cgi?WebService=SetGPTimerChannel"))).transform({ case (header, body) => 
[error]                           ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1544: value toSeq is not a member of Any
[error]               scala.xml.Elem(null, "Body", scala.xml.Null, defaultScope, true, body.toSeq: _*)
[error]                                                                                     ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1551: not found: value userCredentials
[error]             scalaxb.toXML(userCredentials, Some("http://www.myservice.com/MyServices/2012/06/18/"), "UserCredentials", defaultScope), defaultScope, baseAddress, "POST", Some(new java.net.URI("http://1.1.1.1/cgi-bin/cgi.cgi?WebService=SomeServiceCall"))).transform({ case (header, body) => 
[error]                           ^
[error] /Users/joe/Desktop/scalaxb-soap-example/target/scala-2.11/src_managed/main/sbt-scalaxb/myservice/xmlprotocol.scala:1553: value toSeq is not a member of Any
[error]               scala.xml.Elem(null, "Body", scala.xml.Null, defaultScope, true, body.toSeq: _*)
[error]                                                                                     ^

Any ideas what and why I'm facing this issue? Here is my build.sbt:

import ScalaxbKeys._

val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "1.0.2"
val scalaParser = "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.1"
val dispatchV = "0.11.1" // change this to appropriate dispatch version
val dispatch = "net.databinder.dispatch" %% "dispatch-core" % dispatchV

organization := "com.eon"

name := "scalaxb-myservice-sample"

scalaVersion := "2.11.6"

scalaxbSettings

packageName in (Compile, scalaxb) := "rdmservice"

dispatchVersion in (Compile, scalaxb) := dispatchV

async in (Compile, scalaxb) := true

sourceGenerators in Compile <+= scalaxb in Compile

libraryDependencies ++= Seq(scalaXml, scalaParser, dispatch)

Solution

  • If you only need to generate WSDL client code, using scalaxb might be a bit too much. As an option, you could just use wsimport wrapped as a simple SBT task that would be executed before the main code compilation. Apart from one less dependency, it also keeps your repository pristine and frees it from committing the generated boilerplate Java code. Here's a sample template project if anyone is interested: https://github.com/sainnr/sbt-scala-wsdl-template.