Fala Pessoal,
Estou tendo dificuldades para consumir o webservice de statusServico na receita, no meu caso acho que o problema é o meu cliente, nao posso utilizar os recursos do jax-ws, tenho que fazer um cliente simples, só com uma classe, algum de vcs ja fez isso, para versao 1.2 consegui fazer, porem para essa primeira versao da nf-e que é com soap 1.1 nao esta funfando.
Segue abaixo meu codigo e o erro que esta dando quando executo.
public static void main(String[] args) {
String envelope = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "+
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> "+
"<soapenv:Body>"+
"<nfeStatusServicoNF soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> "+
"<nfeCabecMsg xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"> "+
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><cabecMsg versao=\"1.02\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.portalfiscal.inf.br/nfe\" xmlns=\"http://www.portalfiscal.inf.br/nfe\"><versaoDados>1.07</versaoDados></cabecMsg>"+
"</nfeCabecMsg> "+
"<nfeDadosMsg xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"> "+
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><consStatServ versao=\"1.07\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.portalfiscal.inf.br/nfe\" xmlns=\"http://www.portalfiscal.inf.br/nfe\"><tpAmb>2</tpAmb><cUF>31</cUF><xServ>STATUS</xServ></consStatServ>"+
"</nfeDadosMsg> "+
"</nfeStatusServicoNF> "+
"</soapenv:Body> "+
"</soapenv:Envelope>";
metodo2(envelope, "https://nfe.fazenda.mg.gov.br/nfe/services/NfeStatusServico");
}
public static void metodo2(String envelope, String urlAddress) {
try {
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage message;
try {
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
System.setProperty("javax.net.ssl.keyStore", "C:\\TEsteCertificado.pfx");
System.setProperty("javax.net.ssl.keyStorePassword", "serasa");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "C:\\Raiz.jks");
MimeHeaders header = new MimeHeaders();
header.addHeader("Content-Type", "text/xml; charset=utf-8");
//header.addHeader("SOAPAction", "http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico/nfeStatusServicoNF");
message = factory.createMessage(header, new ByteArrayInputStream(envelope.getBytes()));
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
URL url = new URL(urlAddress);
System.out.println("Message enviada \n"+message.toString());
SOAPMessage res = con.call(message, url);
ByteArrayOutputStream in = new ByteArrayOutputStream();
message.writeTo(in);
System.out.println("in :\n"+in.toString());
ByteArrayOutputStream out = new ByteArrayOutputStream();
res.writeTo(out);
System.out.println("out :\n"+out.toString());
} catch (IOException ex) {
System.out.println("" + ex.getMessage());
} finally {
}
} catch (SOAPException ex) {
System.out.println("" + ex.getMessage());
}
}
Este é o meu rotorno que estou tendo do webservice:
<soap:Envelope xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Could not read XML stream… Nested exception is com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target (“xml”); xml (case insensitive) is reserved by the specs.
at [row,col {unknown-source}]: [1,380]</faultstring></soap:Fault></soap:Body></soap:Envelope>
Obrigado.
att
Diego