Ola pessoal, ja vim aqui por varias vezes com uma duvida sobre como passar o header no SOAP 1.2 usando o jax-ws, muitos aqui migraram pro Axis2 mas não é meu caso, preciso fazer com o jax-ws então vamos venho a perguntar aos feras do java como poso resolver isso:
meus métodos de conumo ao web service:
@WebServiceRef(wsdlLocation = "file:/.../NFeStatusServico2.wsdl")
br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeStatusServico2 webServiceClient = null;
@Override
protected Object getResponse(String nfeDadosMsg) throws Problem {
try {
NfeStatusServicoNF2Result nfeStatusServicoNF2Result = null;
webServiceClient = new br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeStatusServico2();
System.out.println("Coletando a porta do servico: " + webServiceClient);
// Tentei reolver o problema colocando um handler que insere um header no soap mas não funcionou:
// webServiceClient.setHandlerResolver(new HandlerResolver() {
// @Override
// public List<Handler> getHandlerChain(PortInfo portInfo) {
// List<Handler> handlers = new ArrayList<Handler>();
// handlers.add(new NfeStatusServico2Handler());
// return handlers;
// }
// });
br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeStatusServico2Soap12 port = webServiceClient.getNfeStatusServico2Soap12();
System.out.println("Porta SOAP que esta sendo invocada: " + port);
br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeCabecMsg nfeCabecMsg = new br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeCabecMsg();
nfeCabecMsg.setCUF("43");
nfeCabecMsg.setVersaoDados("2.00");
// WSBindingProvider bp = (WSBindingProvider) port;
// bp.setOutboundHeaders(Headers.create(new QName("http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"), "SOAPAction"));
System.out.println("***");
System.out.println("DadosCTE: " + nfeDadosMsg.toString());
System.out.println("***");
NfeDadosMsg nfeDadosMsg1 = new NfeDadosMsg();
// // add nfeCabebc na nfeDadosMsg, isso faz o header ir para dentro do body o que não é o caso ja que um header fica dentro da tag <S:Envelope e tambem o //body
// nfeDadosMsg1.getContent().add(new ObjectFactory().createNfeCabecMsg(nfeCabecMsg));
nfeDadosMsg1.getContent().add(nfeDadosMsg);
br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeStatusServicoNF2Result result = port.nfeStatusServicoNF2(nfeDadosMsg1);
System.out.println("Resposta do servico: " + nfeStatusServicoNF2Result.getContent().toString());
System.out.println("Result = " + result);
System.out.println("Resposta = " + Arrays.toString(result.getContent().toArray()));
return getBeanFromString(new RetConsStatServ(), nfeStatusServicoNF2Result.getContent().toString());
} catch (SOAPException ex) {
Logger.getLogger(WebServiceStatus.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(WebServiceStatus.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
agora vou mostrar o log do meu SOAP:
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/web] has already been started
Coletando a porta do servico: br.inf.portalfiscal.nfe.wsdl.nfestatusservico2.NfeStatusServico2@523df
Porta SOAP que esta sendo invocada: JAX-WS RI 2.1.1 in JDK 6: Stub for https://homologacao.nfe.sefaz.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx
***
DadosCTE: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><consStatServ xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00"><tpAmb>2</tpAmb><cUF>43</cUF><xServ>STATUS</xServ></consStatServ>
***
---[HTTP request]---
SOAPAction: ""
Accept: application/soap+xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type: application/soap+xml; charset=utf-8;action="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2/nfeStatusServicoNF2"
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
<S:Body>
<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><consStatServ xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.00"><tpAmb>2</tpAmb><cUF>43</cUF><xServ>STATUS</xServ></consStatServ></nfeDadosMsg>
</S:Body>
</S:Envelope>--------------------
---[HTTP response 500]---
null: HTTP/1.1 500 Internal Server Error
Cache-control: private
Content-type: application/soap+xml; charset=utf-8
Content-length: 618
X-powered-by: ASP.NET
Server: Microsoft-IIS/6.0
Date: Thu, 13 May 2010 18:45:56 GMT
X-aspnet-version: 2.0.50727
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Server was unable to read request. ---> There is an error in XML document (1, 483).
---> The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type.
</soap:Text>
</soap:Reason><soap:Detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>--------------------
por favor alguem que tenha implementado com o jaxws me ajuda a resolver esse rolo ?
notem que o soapAcation est vazio SOAPAction: “”
se eu adicionar o nfeCabec dentro do body ele da não da essa menssagem de que os dados estão do tipo errado, ele reclama que falta o cabeçalho dando erro 242 que é referente a falta do cabeçalho, bem é isso, abraços.