【发布时间】:2019-08-06 11:22:47
【问题描述】:
我正在尝试使用 jax-ws 生成一个 xml 有效负载,但没有成功。服务器期望所有命名空间都在信封标签中。例如:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://somewhere.namespace1.com" xmlns:ns2="http://somewhere.namespace2.com">
是我需要的,而
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
是我所拥有的。
jax-ws 生成像
这样的有效负载<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns1:Element1 xmlns:ns1="http://somewhere.namespace1.com" xmlns:ns1="http://somewhere.namespace2.com">
<ns2:Element2>value</ns2:Element2>
</ns1:Element1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但我需要
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://somewhere.namespace1.com" xmlns:ns2="http://somewhere.namespace2.com">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns1:Element1>
<ns2:Element2>value</ns2:Element2>
</ns1:Element1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我尝试将package-info.java 文件与@javax.xml.bind.annotation.XmlSchema 放在一起,我能够更改前缀但不能将实际的命名空间声明从子节点移动到根节点。例如,我可以(显然?)在信封中定义我需要的所有命名空间
@javax.xml.bind.annotation.XmlSchema(
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = {
@XmlNs(
prefix = "ns1",
namespaceURI="http://somewhere.namespace1.com"),
@XmlNs(
prefix = "ns2",
namespaceURI="http://somewhere.namespace2.com"),
}
)
但是在Element1.java 和Element2.java 所在的package-info.java 中,我不想在那里定义命名空间。我试过了
@javax.xml.bind.annotation.XmlSchema(
namespace="http://schemas.xmlsoap.org/soap/envelope/",
location = ""
)
但它不起作用。
有没有其他人遇到过类似的问题?我确定这只是注释的问题,但我一直无法弄清楚。
【问题讨论】:
-
我假设您已经使用“wsimport”来生成必要的客户端文件,这些文件将生成接口和实现文件。您还可以共享用于生成请求的 Java Web 服务客户端的代码吗?
标签: java xml soap jax-ws xml-namespaces