我正在尝试使用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"), } )
但是在
package-info.java
和Element1.java
所在的Element2.java
中,我不想在那里定义名称空间。我已经尝试过
@javax.xml.bind.annotation.XmlSchema( namespace="http://schemas.xmlsoap.org/soap/envelope/", location = "" )
但是它不起作用。
还有其他人有类似的问题吗?我敢肯定这只是注解的问题,但我一直无法弄清楚。
我正在尝试使用jax-ws生成xml有效负载,但无法正常工作。服务器希望所有名称空间都在信封标记中。例如:
我通过使用Spring的WebServiceTemplate#sendAndReceive(String, WebServiceMessageCallback, WebServiceMessageExtractor<T>)
进行调用解决了这个问题,其中在第二个参数(回调)中,我手动添加了需要在标头中使用的名称空间。例如类似
wsResponse = this.webServiceTemplate.sendAndReceive(uri,
(webServiceMessage) -> {
...
SoapMessage soapMessage = (SoapMessage) webServiceMessage;
...
final SoapEnvelope envelope = soapMessage.getEnvelope();
headerNamespaces.forEach(envelope::addNamespaceDeclaration);
...
}, this.responseExtractor);