I’m trying to make a soap request to a Brazilian government endpoint and I’m facing some trouble.
They make the following wsdl available: https://mdfe-homologacao.svrs.rs.gov.br/ws/MDFeRecepcaoSinc/MDFeRecepcaoSinc.asmx?wsdl
I then generated the corresponding stub using wsimport tool, which consists on the following:
- MDFeRecepcaoSinc.java
- MdfeRecepcaoResult.java
- MDFeRecepcaoSincSoap12.java (interface)
- ObjectFactory.java
- package-info.java
Then, on my Java application, I did the following:
ObjectFactory of = new ObjectFactory();
JAXBElement<String> jaxb = of.createMdfeDadosMsg("<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mdf="http://www.portalfiscal.inf.br/mdfe/wsdl/MDFeRecepcaoSinc"><soap:Header/><soap:Body><mdf:mdfeDadosMsg>?</mdf:mdfeDadosMsg></soap:Body></soap:Envelope>");
MDFeRecepcaoSinc recepcao = new MDFeRecepcaoSinc();
MDFeRecepcaoSincSoap12 soap = recepcao.getMDFeRecepcaoSincSoap12(
// new AddressingFeature(true),
// new MTOMFeature(false),
// new RespectBindingFeature(true)
);
System.out.println(soap.mdfeRecepcao(jaxb.getValue()).getContent());
Although the only result I’m getting, independent of the body text, is [[retMDFe: null]]
.
I managed to make it work on SoapUI with this exact same request envelope and it returns a correct xml with a few tags inside retMDFe
.
It appears to be connecting to their server from my Java client since the tag retMDFe
isn’t present in the WSDL file or any stub I generated, and since I don’t receive the 403 - Forbidden
error anymore (configured the system keystore correctly).
Unfortunately, this webservice only allows connections issued with a digital certificate.
I’m suspecting the error may be from the mapping from the endpoint to the MdfeRecepcaoResult class.
I’ve tried a few things:
- enabling different WebServiceFeatures on the constructor of recepcao.getMDFeRecepcaoSincSoap12, although only MTOMFeature as true returned something different:
Client received SOAP Fault from server: Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1. Please see the server log to find more detail regarding exact cause of the failure.
; - changing mdfeRecepcao return type from MdfeRecepcaoResult to String, which gave me an empty string;
- commenting annotations on mdfeRecepcao, which continued to give me the
[[retMDFe: null]]
response; - also tried passing different xml strings directly to soap.mdfeRecepcao() method, but got the same results.
What am I possibly doing wrong here? Thank you for your time!
Edit 1:
- Declaration of mdfeRecepcao inside MDFeRecepcaoSincSoap12 interface:
/**
*
* @param mdfeDadosMsg
* @return
* returns br.inf.portalfiscal.mdfe.wsdl.mdferecepcaosinc.MdfeRecepcaoResult
*/
@WebMethod(action = "http://www.portalfiscal.inf.br/mdfe/wsdl/MDFeRecepcaoSinc/mdfeRecepcao")
@WebResult(name = "mdfeRecepcaoResult", targetNamespace = "http://www.portalfiscal.inf.br/mdfe/wsdl/MDFeRecepcaoSinc", partName = "mdfeRecepcaoResult")
public MdfeRecepcaoResult mdfeRecepcao(
@WebParam(name = "mdfeDadosMsg", targetNamespace = "http://www.portalfiscal.inf.br/mdfe/wsdl/MDFeRecepcaoSinc", partName = "mdfeDadosMsg")
String mdfeDadosMsg);
- Declaration of createMdfeDadosMsg inside ObjectFactory class
/**
* Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://www.portalfiscal.inf.br/mdfe/wsdl/MDFeRecepcaoSinc", name = "mdfeDadosMsg")
public JAXBElement<String> createMdfeDadosMsg(String value) {
return new JAXBElement<String>(_MdfeDadosMsg_QNAME, String.class, null, value);
}
Edit 2:
-
wsimport version:
wsimport version "2.2.9"
-
wsimport generated files:
br/inf/portalfiscal/mdfe/wsdl/mdferecepcaosinc/MDFeRecepcaoSinc.java
br/inf/portalfiscal/mdfe/wsdl/mdferecepcaosinc/MDFeRecepcaoSincSoap12.java
br/inf/portalfiscal/mdfe/wsdl/mdferecepcaosinc/MdfeRecepcaoResult.java
br/inf/portalfiscal/mdfe/wsdl/mdferecepcaosinc/ObjectFactory.java
br/inf/portalfiscal/mdfe/wsdl/mdferecepcaosinc/package-info.java
I use the following to produce the stubs: wsimport -extension -keep -verbose MDFeRecepcaoSinc.wsdl
and it only gives a single warning: [WARNING] a porta SOAP "MDFeRecepcaoSincSoap12": usa um bind de SOAP 1.2 não padrão. linha 40 de file:/home/teste-progra/tiago/backup/mdfe/wsimport-test/MDFeRecepcaoSinc.wsdl
(which means that the port used by the web service does not use a conventional (or default) bind for SOAP 1.2, and has to do with the following line in the wsdl:
<wsdl:port name="MDFeRecepcaoSincSoap12" binding="tns:MDFeRecepcaoSincSoap12">
I’m not sure if that’s of any use though, hence the connection is effectively being held on.
DevSoloDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You are not correctly marshalling the element here.
JAXBElement<String> jaxb = of.createMdfeDadosMsg("<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mdf="http://www.portalfiscal.inf.br/mdfe/wsdl/MDFeRecepcaoSinc"><soap:Header/><soap:Body><mdf:mdfeDadosMsg>?</mdf:mdfeDadosMsg></soap:Body></soap:Envelope>");
You should send a marshalled object request to the soap WS, something like this :
// Assuming MdfeDadosMsg is a class annotated with JAXB annotations and generated during your wsimport
MdfeDadosMsg requestObject = new MdfeDadosMsg();
//set your required data according to the WSDL for the requestObject.
ObjectFactory of = new ObjectFactory();
JAXBElement<MdfeDadosMsg> jaxb = of.createMdfeDadosMsg(requestObject);
MDFeRecepcaoSinc recepcao = new MDFeRecepcaoSinc();
MDFeRecepcaoSincSoap12 soap = recepcao.getMDFeRecepcaoSincSoap12();
MdfeRecepcaoResult response = soap.mdfeRecepcao(jaxb);
2