ActiveDelphi - Índice do Fórum ActiveDelphi
.: O site do programador Delphi! :.
 
 FAQFAQ   PesquisarPesquisar   MembrosMembros   GruposGrupos   RegistrarRegistrar 
 PerfilPerfil   Entrar e ver Mensagens ParticularesEntrar e ver Mensagens Particulares   EntrarEntrar 

Passar um Certificado no HTTPRIO

 
Novo Tópico   Responder Mensagem    ActiveDelphi - Índice do Fórum -> Delphi
Exibir mensagem anterior :: Exibir próxima mensagem  
Autor Mensagem
vcscastro
Novato
Novato


Registrado: Quarta-Feira, 5 de Novembro de 2014
Mensagens: 17
Localização: Belo Horizonte

MensagemEnviada: Seg Jan 23, 2017 8:15 am    Assunto: Passar um Certificado no HTTPRIO Responder com Citação

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
Ver o perfil de Usuários Enviar Mensagem Particular
johnny-walker
Moderador
Moderador


Registrado: Sábado, 4 de Outubro de 2003
Mensagens: 10653
Localização: Contagem/MG - BRAZIL

MensagemEnviada: Qua Jan 25, 2017 8:53 am    Assunto: Responder com Citação

Tente estes links que achei, talvez resolva seu problema:


http://www.codenewsfast.com/cnf/article/0/permalink.art-ng1920q1136
http://qc.embarcadero.com/wc/qcmain.aspx?d=118831



bye
_________________
P.O.W.E.R B.Y D.E.L.P.H.I
Voltar ao Topo
Ver o perfil de Usuários Enviar Mensagem Particular MSN Messenger
vcscastro
Novato
Novato


Registrado: Quarta-Feira, 5 de Novembro de 2014
Mensagens: 17
Localização: Belo Horizonte

MensagemEnviada: Qua Jan 25, 2017 9:09 am    Assunto: Responder com Citação

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
Ver o perfil de Usuários Enviar Mensagem Particular
natanbh1
Colaborador
Colaborador


Registrado: Terça-Feira, 15 de Março de 2011
Mensagens: 3093
Localização: Belo Horizonte - MG

MensagemEnviada: Qua Jan 25, 2017 9:23 am    Assunto: Responder com Citação

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
Ver o perfil de Usuários Enviar Mensagem Particular Enviar E-mail
johnny-walker
Moderador
Moderador


Registrado: Sábado, 4 de Outubro de 2003
Mensagens: 10653
Localização: Contagem/MG - BRAZIL

MensagemEnviada: Sex Jan 27, 2017 9:57 am    Assunto: Responder com Citação

Ou pode ser a unit JwaWinCrypt.pas.

A propósito, acredito ser da jedi esta unit.
http://sourceforge.net/projects/jedi-apilib/


bye
_________________
P.O.W.E.R B.Y D.E.L.P.H.I
Voltar ao Topo
Ver o perfil de Usuários Enviar Mensagem Particular MSN Messenger
kawasoft
Novato
Novato


Registrado: Quarta-Feira, 4 de Abril de 2018
Mensagens: 1

MensagemEnviada: Qua Abr 04, 2018 2:34 pm    Assunto: nfe 4.0 Responder com Citação

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
Ver o perfil de Usuários Enviar Mensagem Particular
Mostrar os tópicos anteriores:   
Novo Tópico   Responder Mensagem    ActiveDelphi - Índice do Fórum -> Delphi Todos os horários são GMT - 3 Horas
Página 1 de 1

 
Ir para:  
Enviar Mensagens Novas: Proibido.
Responder Tópicos Proibido
Editar Mensagens: Proibido.
Excluir Mensagens: Proibido.
Votar em Enquetes: Proibido.


Powered by phpBB © 2001, 2005 phpBB Group
Traduzido por: Suporte phpBB