Request is not built properly

11 views
Skip to first unread message

Álvaro Castellanos López

unread,
Dec 23, 2020, 3:52:53 AM12/23/20
to scalaxb
hi!

I've seen that on XMLProtocol, targetNamespace is generated as a None defaultScope. In my case, this hampers that a request has been well built.
Let's me explain this with an example. Having this wsdl:

```
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
    xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:tns="http://myservice.com/service/login"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    targetNamespace="http://myservice.com/service/login"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://myservice.com/service/login">
      <s:element name="getAuth">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" form="unqualified" name="user" type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" form="unqualified" name="password" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      .
      .
      .

```

what I get as a request for `getAuth` is:

```
<soap11:Envelope
xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://myservice.com/service/login"
xmlns="http://myservice.com/service/login">
    <soap11:Body>
        <getAuth>
            <user>user</user>
            <password>password</password>
        </getAuth>
    </soap11:Body>
</soap11:Envelope>

```

and because `<getAuth>` doesn't have `tns` we get:

```
System.Web.Services.Protocols.SoapException: The element 'getAuth' in namespace 'http://myservice.com/service/login' has invalid child element 'user' in namespace 'http://myservice.com/service/login'. List of possible elements expected: 'user'.
```

I've realized that removing `None -> "http://myservice.com/service/login"` from `defaultScope`

```
trait XMLProtocol extends scalaxb.XMLStandardTypes {
  val defaultScope = scalaxb.toScope(None -> "http://myservice.com/service/login",
    Some("tns") -> "http://myservice.com/service/login",
    Some("xs") -> "http://www.w3.org/2001/XMLSchema",
    Some("xsi") -> "http://www.w3.org/2001/XMLSchema-instance")
...

```

this is solved and the request is well built:

```
<soap11:Envelope
xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://myservice.com/service/login">
    <soap11:Body>
        <tns:getAuth>
            <user>user</user>
            <password>password</password>
        </tns:getAuth>
    </soap11:Body>
</soap11:Envelope>

```

So, my question is, how can I fix this?

We use sbt-scalaxb 1.8.0, scala 2.13.4 and this is part of my build.sbt

```
  lazy val scalaXml           = "org.scala-lang.modules"       %% "scala-xml"                % "2.0.0-M2"
  lazy val scalaParser        = "org.scala-lang.modules"       %% "scala-parser-combinators" % "1.1.2"
  lazy val dispatch           = "org.dispatchhttp"             %% "dispatch-core"            % "1.1.3"

...

    .enablePlugins(ScalaxbPlugin)
    .settings(
      scalacOptions ++= Seq("-Wconf:src=src_managed/.*:silent"),
      sourceGenerators in Compile += (scalaxb in Compile).taskValue,
      scalaxbPackageName in (Compile, scalaxb) := "generated",
      scalaxbDispatchVersion in (Compile, scalaxb) := "1.1.3"
    )

```

Please, let me know if I need to report something else to clarify this. I hope someone can help me. Thanks :)
Reply all
Reply to author
Forward
0 new messages