title: No namespace in nested tags in SOAP message with JAX-WS
body: <p>I am trying to write a Java application that consumes a given web service, using JAX-WS and wsimport. The SOAP message that it sends to the service is mostly correct. However, on of the parameters passed to the service function is an array of strings. Although the array itself is given the proper namespace in the SOAP XML, elements ('parm' in the message below) have no namespace. This causes the service to fail.</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;S:Body&gt;
          &lt;ns2:Submit xmlns:ns2="http://www.acme.com/service/wsdl"&gt;
              &lt;ns2:service&gt;SomeJob&lt;/ns2:service&gt;
              &lt;ns2:parms&gt;
                  &lt;parm&gt;someparam&lt;/parm&gt;
                  &lt;parm&gt;anotherparam&lt;/parm&gt;
              &lt;/ns2:parms&gt;
          &lt;/ns2:Submit&gt;
      &lt;/S:Body&gt;
  &lt;/S:Envelope&gt;
  </code></pre>
  
  <p>The <code>&lt;parm&gt;</code> elements should have read <code>&lt;ns2:parm&gt;</code>, or alternatively the <code>&lt;Submit&gt;</code> tag could have defined a default namespace <code>&lt;Submit xmlns="http://www.acme.com/service/wsdl"&gt;</code> (that is what the service suggests in an example SOAP message).</p>
  
  <p>This question does resemble the one in <a href="https://stackoverflow.com/questions/5793352/jax-ws-why-nested-elements-are-in-namespace">JAX-WS: why nested elements are in &quot;&quot; namespace?</a>. However there changing the style from RPC/Literal to Document/Wrapped solved the issue, while in my case the service is Document/Wrapped to begin with.</p>
  
  <p>How can I convince the JAX-WS library to generate namespaces on the nested elements in the array?</p>
  
  <p>TIA,
  Jeroen</p>
  
  <p><strong>Update</strong>: Editing the generated code appears to work. Someone suggested adding a namespace attribute to the @XmlElement line preceeding the definition of 'parm' in the generated array type:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "ArrayOfString", propOrder = {
      "parm"
  })
  public class ArrayOfString {
  
  @XmlElement(nillable = true, namespace="http://www.acme.com/service/wsdl")
  protected List&lt;String&gt; parm;
  ...
  }
  </code></pre>
  
  <p>This causes JAX-WS to add the namespace and will probably solve the issue. As code generation is, in this case, done only once, editing the generated code is acceptable. Still I wonder whether there isn't a better solution.</p>