I'm developing a WebService application using jax-ws. In this model, after importing the WSDL, the IDE generates the classes that will be used in the information exchange. However when I create the object and pass as a parameter I get the message from the server:
undeclared namespace prefix 'x' at offset 143 of link
When I do the marshalling of the object to check the XML if it is correct I get:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ans:solicitacaoProcedimentoWS xmlns:ans="http://exemplo"
xmlns:ns2="http://www.w3.org/2000/09/xmldsig#">
<ans:cabecalho>
...
</ans:cabecalho>
...
However, I must inform this namespace in the header as follows:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ans="http://exemplo" xmlns:xd="http://www.w3.org/2000/09/xmldsig#">
<soapenv:Header/>
<soapenv:Body>
<ans:solicitacaoProcedimentoWS>
...
</ans:solicitacaoProcedimentoWS>
...
Below the code that converts the object to XML:
public static String converteBeanXML(Object bean) {
try {
Writer writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(bean.getClass());
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(bean, writer);
return writer.toString();
} catch (JAXBException ex) {
escreveLogErro(ex.getMessage(), "SisUtil.converteBeanXML()");
return null;
}
}
How do I make this declaration of namespaces in the XML header if all classes were generated when I imported WSDL?