1
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 exchanges. But when creating the object and passing as parameter I receive the message from the server:
undeclared namespace prefix 'x' at offset 143 of http://urlexample.com
When I marshalling the object to check the XML 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>
...
but 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 should I make this namespace statement in the XML header if all classes were generated when I imported the WSDL?
Post the code on which you mount this XML
– Marquezani
@Marquezani was just that?
– Edward Neto
In this snippet you generate pure XML without the SOAP envelope. Do you have the code that generates the SOAP envelope? Post it please
– Marquezani