问题
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.
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:Submit xmlns:ns2="http://www.acme.com/service/wsdl">
<ns2:service>SomeJob</ns2:service>
<ns2:parms>
<parm>someparam</parm>
<parm>anotherparam</parm>
</ns2:parms>
</ns2:Submit>
</S:Body>
</S:Envelope>
The <parm>
elements should have read <ns2:parm>
, or alternatively the <Submit>
tag could have defined a default namespace <Submit xmlns="http://www.acme.com/service/wsdl">
(that is what the service suggests in an example SOAP message).
This question does resemble the one in JAX-WS: why nested elements are in "" namespace?. 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.
How can I convince the JAX-WS library to generate namespaces on the nested elements in the array?
TIA, Jeroen
Update: 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:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfString", propOrder = {
"parm"
})
public class ArrayOfString {
@XmlElement(nillable = true, namespace="http://www.acme.com/service/wsdl")
protected List<String> parm;
...
}
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.
回答1:
You can also influence the namespace creation by adding
elementFormDefault="qualified"
either to your Java @XmlSchema
annotation - or in your case - to the XSD defining the service.
来源:https://stackoverflow.com/questions/15616805/no-namespace-in-nested-tags-in-soap-message-with-jax-ws