Web Server qtsoap
-
How to create and send a xml to a web server.
The XML looks like this:
@
POST /NfeRecepcao2/NfeRecepcao2.asmx HTTP/1.1
Host: www.sefazvirtual.fazenda.gov.br
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.portalfiscal.inf.br/nfe/wsdl/NfeRecepcao2/nfeRecepcaoLote2"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
soap:Header
<nfeCabecMsg >
<versaoDados>string</versaoDados>
<cUF>string</cUF>
</nfeCabecMsg>
</soap:Header>
soap:Body
<nfeDadosMsg >file .xml</nfeDadosMsg>
</soap:Body>
</soap:Envelope>@I need create and send using qtsoap or something else.
I created but was not equal.@
QtSoapMessage msg;transport.setHost("www.sefazvirtual.fazenda.gov.br",443); connect(&transport, SIGNAL(responseReady()),this,SLOT(getResponse())); msg.setMethod("nfeDadosMsg","http://www.portalfiscal.inf.br/nfe/wsdl/NfeRecepcao2"); msg.addMethodArgument("versaoDados","","2.0"); msg.addMethodArgument("cUF","","MA"); msg.addMethodArgument("nfeDadosMsg","","C:\\QtSDK\\QtCreator\\NFe\\testaNFe\\arquivo.xml"); transport.setAction("http://www.portalfiscal.inf.br/nfe/wsdl/NfeRecepcao2/nfeRecepcaoLote2"); transport.submitRequest(msg, "/nfeRecepcao/nfeRecepcao2.asmx");
//======
//out
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<nfeDadosMsg >
<versaoDados xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">2.0</versaoDados>
<cUF xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">MA</cUF>
<nfeDadosMsg xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">C:\QtSDK\QtCreator\NFe\testaNFe\arquivo.xml</nfeDadosMsg>
</nfeDadosMsg>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>@
-
"versaoDados" and "cUF" are not method arguments. In your example they are in the SOAP Header. I am not sure if the qtsoap implementation had support for SOAP Header Entries.
If this is your only request (or one of only a few) it may be easier to simply use QXmlStreamWriter to produce exactly the XML you want.
-
ok, i believe too that qtsoap can not implement the header. If i create with the QXmlStreamWrite how can i send for a web server using the Qt?
-
You can post HTTP requests and receive responses using "QNetworkAccessManager":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html. You would pass the output from QXmlStreamWrite to post() along with a "QNetworkRequest":http://qt-project.org/doc/qt-4.8/qnetworkrequest.html object. You can set the "SOAPAction" value in the request using its setRawHeader method and the content type using setHeader (as its a known header). You will receive your response in the form of a "QNetworkReply":http://qt-project.org/doc/qt-4.8/qnetworkreply.html via the managers finished signal.
I've just finished creating a custom JSON-RPC library using this method and these classes and its works very nicely.
-
Thanks guys, I'm using QNetWorkAccessManeger and everything is ok now.
;)