 |
ActiveDelphi .: O site do programador Delphi! :.
|
| Exibir mensagem anterior :: Exibir próxima mensagem |
| Autor |
Mensagem |
vcscastro Novato

Registrado: Quarta-Feira, 5 de Novembro de 2014 Mensagens: 17 Localização: Belo Horizonte
|
Enviada: Seg Jan 23, 2017 8:15 am Assunto: Passar um Certificado no HTTPRIO |
|
|
Pessoal,
Estou em uma tarefa onde temos que Consumir um WS com HTTPS.
Infelizmente não podemos usar a biblioteca ACBr, que já tem a funcionalidade desenvolvida.
Precisamos consumir um WS da Sefaz.
Usamos o wizard do Delphi para gerar os stubs passando a URL. Quando vamos enviar, o sistema pede para selecionar o certificado que esta instalado no maquina e começa o processo de envio.
No meio do processo ele acusa o seguinte erro:
| Citação: | | É necessário um certificado para concluir a autenticação do cliente - URL da Sefaz... |
Abaixo o Codigo
Código gerado pelo Delphi
| Código: |
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : https://hom.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx?wsdl
// >Import : https://hom.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx?wsdl>0
// Encoding : utf-8
// Version : 1.0
// (23/01/2017 08:45:33 - - $Rev: 86412 $)
// ************************************************************************ //
unit NFeDistribuicaoDFe;
interface
uses Soap.InvokeRegistry, Soap.SOAPHTTPClient, System.Types, Soap.XSBuiltIns;
const
IS_OPTN = $0001;
IS_REF = $0080;
type
// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Embarcadero types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:schema - "http://www.w3.org/2001/XMLSchema"[Gbl]
nfeDadosMsg = TXMLData; { "http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe"[CplxMxd] }
nfeDistDFeInteresseResult = TXMLData; { "http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe"[CplxMxd] }
// ************************************************************************ //
// Namespace : http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe
// soapAction: http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe/nfeDistDFeInteresse
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// use : literal
// binding : NFeDistribuicaoDFeSoap
// service : NFeDistribuicaoDFe
// port : NFeDistribuicaoDFeSoap
// URL : https://hom.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx
// ************************************************************************ //
NFeDistribuicaoDFeSoap = interface(IInvokable)
['{61C18AB5-7DEC-D3AB-9145-8DE2C0B60BD1}']
function nfeDistDFeInteresse(const nfeDadosMsg: nfeDadosMsg): nfeDistDFeInteresseResult; stdcall;
end;
function GetNFeDistribuicaoDFeSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): NFeDistribuicaoDFeSoap;
implementation
uses System.SysUtils;
function GetNFeDistribuicaoDFeSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): NFeDistribuicaoDFeSoap;
const
defWSDL = 'https://hom.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx?wsdl';
defURL = 'https://hom.nfe.fazenda.gov.br/NFeDistribuicaoDFe/NFeDistribuicaoDFe.asmx';
defSvc = 'NFeDistribuicaoDFe';
defPrt = 'NFeDistribuicaoDFeSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as NFeDistribuicaoDFeSoap);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
initialization
{ NFeDistribuicaoDFeSoap }
InvRegistry.RegisterInterface(TypeInfo(NFeDistribuicaoDFeSoap), 'http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(NFeDistribuicaoDFeSoap), 'http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe/nfeDistDFeInteresse');
InvRegistry.RegisterInvokeOptions(TypeInfo(NFeDistribuicaoDFeSoap), ioDocument);
{ NFeDistribuicaoDFeSoap.nfeDistDFeInteresse }
InvRegistry.RegisterMethodInfo(TypeInfo(NFeDistribuicaoDFeSoap), 'nfeDistDFeInteresse', '',
'[ReturnName="nfeDistDFeInteresseResult"]', IS_OPTN);
RemClassRegistry.RegisterXSInfo(TypeInfo(nfeDadosMsg), 'http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe', 'nfeDadosMsg');
RemClassRegistry.RegisterXSInfo(TypeInfo(nfeDistDFeInteresseResult), 'http://www.portalfiscal.inf.br/nfe/wsdl/NFeDistribuicaoDFe', 'nfeDistDFeInteresseResult');
end.
|
Código onde estou chamando
| Código: |
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Soap.XSBuiltIns,
NFeDistribuicaoDFe, Data.DB, Datasnap.DBClient, Soap.SOAPConn;
type
TForm3 = class(TForm)
Button1: TButton;
SoapConnection1: TSoapConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
retor: String;
nfeDadosMsg, nfeDistDFeInteresseResult: TXMLData;
DFeSoap: NFeDistribuicaoDFeSoap;
begin
try
begin
nfeDadosMsg := TXMLData.Create;
DFeSoap := GetNFeDistribuicaoDFeSoap(true, '', nil);
nfeDadosMsg.LoadFromXML('<distDFeInt><tpAmb>2</tpAmb><cUFAutor>31</cUFAutor><CPF>02603104683</CPF><distNSU><ultNSU>000000000000000</ultNSU></distNSU></distDFeInt>');
nfeDistDFeInteresseResult:= DFeSoap.nfeDistDFeInteresse(nfeDadosMsg);
end
except
on E: Exception do
ShowMessage(E.ToString);
end;
end;
end.
|
Estamos usando Delphi XE 10 Berlin
Att
Vinicius Castro |
|
| Voltar ao Topo |
|
 |
johnny-walker Moderador


Registrado: Sábado, 4 de Outubro de 2003 Mensagens: 10653 Localização: Contagem/MG - BRAZIL
|
|
| Voltar ao Topo |
|
 |
vcscastro Novato

Registrado: Quarta-Feira, 5 de Novembro de 2014 Mensagens: 17 Localização: Belo Horizonte
|
Enviada: Qua Jan 25, 2017 9:09 am Assunto: |
|
|
Jovem,
Tentei justamente esse código.
Não estou sabendo usar esse cara
| Código: |
PCertContext : PCCERT_CONTEXT;
|
Justamente ele, que esta dando problema. Não sei qual arquivo esse gente fina esta!
Att
Vinicius Castro |
|
| Voltar ao Topo |
|
 |
natanbh1 Colaborador

Registrado: Terça-Feira, 15 de Março de 2011 Mensagens: 3093 Localização: Belo Horizonte - MG
|
Enviada: Qua Jan 25, 2017 9:23 am Assunto: |
|
|
Aparece uma mensagem de erro parecida com esta?
| Código: | | Undeclared identifier: 'PCCERT_CONTEXT' |
Se for, adicione CertHelper na uses do form. _________________ ''A persistência é o caminho para o êxito.''
Charlie Chaplin |
|
| Voltar ao Topo |
|
 |
johnny-walker Moderador


Registrado: Sábado, 4 de Outubro de 2003 Mensagens: 10653 Localização: Contagem/MG - BRAZIL
|
|
| Voltar ao Topo |
|
 |
kawasoft Novato

Registrado: Quarta-Feira, 4 de Abril de 2018 Mensagens: 1
|
Enviada: Qua Abr 04, 2018 2:34 pm Assunto: nfe 4.0 |
|
|
Ola pessoal!
Estou fazendo testes para emissao da nfe, migrando para o nfe 4.0.
via xml binder, so obtenho a resposta : "usar somente o namespace padrao da nfe".
via httpresp obtenho a resposta : "o documento xml deve ter um elemento de nivel superior".
o que estou enviando via httpresp:
<xml>
-<soap12>
-<soap12>
-<nfeDadosMsg>
-<consReciNFe>
<tpAmb>2</tpAmb>
<nRec>351000117843943</nRec>
</consReciNFe>
</nfeDadosMsg>
</soap12>
</soap12> |
|
| Voltar ao Topo |
|
 |
|
|
Enviar Mensagens Novas: Proibido. Responder Tópicos Proibido Editar Mensagens: Proibido. Excluir Mensagens: Proibido. Votar em Enquetes: Proibido.
|
|