Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Error after signed a soap request with certificate.



Permlink Replies: 0
Chris Marisco

Posts: 2
Registered: 5/14/14
Error after signed a soap request with certificate.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2016 10:24 AM
Hi all, I'm having a hard time trying to figure out what is going wrong.
this is a proj. with XE 5.

I got this message:

Debugger Exception Notification

Project Project9.exe raised exception class ERemotableException with message 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: node
at System.Xml.XmlNodeReader..ctor(XmlNode node)
at Serpro.Sped.eFinanceira.WsInternet.WsRecepcao.ReceberLoteEvento(XmlDocument loteEventos)
--- End of inner exception stack trace ---'.

Break Continue Help

after import my Wsdl this my btn click event.

procedure TForm7.Button1Click(Sender: TObject);
var
vWsRecepcaoSoap : WsRecepcaoSoap;
vXmlData : loteEventos;
vHTTPRIO : THTTPRIO;
begin
vHTTPRIO := THTTPRIO.Create( Nil );
vHTTPRIO.WSDLLocation := 'http://www1.receita.fazenda.gov.br/sistemas/e-financeira/documentos/doc-download/WsRecepcao.wsdl';
vHTTPRIO.Service := 'WsRecepcao';
vHTTPRIO.Port := 'WsRecepcaoSoap12';
vHTTPRIO.HTTPWebNode.OnBeforePost := HTTPRIO1HTTPWebNode1BeforePost;
vHTTPRIO.OnBeforeExecute := HTTPRIO1BeforeExecute;
vWsRecepcaoSoap := vHTTPRIO as WsRecepcaoSoap;
vXmlData := TXMLData.Create;
vXmlData.LoadFromXML(
//'<?xml version="1.0" encoding="UTF-8"?> '+
'<eFinanceira xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
'xmlns="http://www.eFinanceira.gov.br/schemas/envioLoteEventos/v1_0_1">'+
' <loteEventos>'+
' <evento id="ID0">'+
' <eFinanceira xmlns="http://www.eFinanceira.gov.br/schemas/evtAberturaeFinanceira/v1_0_0">'+
' <evtCadDeclarante id="ID00000001762">'+
' <ideEvento>'+
' <indRetificacao>1</indRetificacao>'+
' <tpAmb>2</tpAmb>'+
' <aplicEmi>2</aplicEmi>'+
' <verAplic>00000000000000000707</verAplic>'+
' </ideEvento>'+
' <ideDeclarante>'+
' <cnpjDeclarante>02475222000196</cnpjDeclarante>'+
' </ideDeclarante>'+
' <infoCadastro>'+
' <nome>CECM SERV ESTAT ADM DIRETA EST E SANTO</nome>'+
' <enderecoLivre>AV JOAO BATISTA PARRA N 673 EDF ENSEADA TOWER LJ 1 PRAIA DO SUA</enderecoLivre>'+
' <municipio>3205309</municipio>'+
' <UF>ES</UF>'+
' <Pais>BR</Pais>'+
' <paisResidencia>BR</paisResidencia>'+
' </infoCadastro>'+
' </evtCadDeclarante>'+
' <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">'+
' <SignedInfo>'+
' <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>'+
' <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>'+
' <Reference URI="#ID00000001762">'+
' <Transforms>'+
' <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>'+
' <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>'+
' </Transforms>'+
' <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>'+
' <DigestValue>G8kSjLVludtkatDuCm2rLszM7D4=</DigestValue>'+
' </Reference>'+
' </SignedInfo>'+
' <SignatureValue>f7OmvLKjuuRQiX+6tgqBYxB5zBFgxjXMyXOqZkWtLhgW2lP/ZzM7xrnt9HZFBSetIhJNGuPhKysZzf4hZClW1YSEfi2WECb3CNzBCfjzeOA2fEJ/FJXdYdDsAvtzjTbt'+
'E+MqrJW/u9sGNJHJDTtVfdjPwt3Y9NUJJ0SADvDtXPiow71rcpAeg3fQD3IIFlPLyz0WbGiUyzDcsl3pb7L7A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RVvoVSvw3dLGbO9HkaZ3nziwOTKHzq32G0MsQ47g4aoeOt9p9SNZhcUoSXESPgCco'+
'uJSLW2H2SYp7bBBB1hDivWqqhwgDXY+kGkleKgjWrE4KdhXQXzD0hj9OubG/huOBUyRaD3kAGF2yTxqUS4vl/oRicpO3NyPa0f3ScGkKtLsAJUAfnfv9p5JUEpVR5sFf7RoGXvv6zDoZnG7QKxuUR'+
'L+x5/ZV2k5dmNSkcmyCwKKnguytRA/S/UZ1NJ3+G3M4g+nNMuofMlFLYPtGGLWQWEY9i32wARLjo6fwcD26NxRxVRYkUOmMe8GSc7gmfqNSC/+FMqMV12EJdvgui6gytLVaXfC1oAjXwkb0e3pQT7'+
'u0+jZsnfAexAvOCNEfe6Jx9ANOF7KrvOr5Tp33l2lPcGD3PQRMsySUCHb95mu9lZ/lqzEKJjwXJ4z2KCCPQ6Su8FKTgUoYTl2BnTJBBPDw06nLBwqB2EiFWnPr+NF5HEuLDcGTysgoFcll4fPJu3y'+
'2OMeq6OGR3xOhK2FEJx9efYZ6KKtGVrR4l6IieDK9joskSRYzU+ZERjvHD8dWm1U9+QXjQ=</X509Certificate></X509Data></KeyInfo></Signature>'+
' </eFinanceira>'+
' </evento>'+
' </loteEventos></eFinanceira>');

vXmlData := vWsRecepcaoSoap.ReceberLoteEvento(vXmlData);
Memo2.text := vXmlData.XMLNode.XML;

end;

procedure TForm7.HTTPRIO1HTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp;
Data: Pointer);
var
Store : IStore;
Certs : ICertificates;
Cert : ICertificate2;
CertContext : ICertContext;
PCertContext : PCCERT_CONTEXT;
V : OleVariant;
vCertsLista : ICertificates2;
begin
(*
thumbprint of the certificate to use. Look at CAPICOM docs to see
how to find certs using other Id's
*)
(*
thumbprint of the certificate to use. Look at CAPICOM docs to see
how to find certs using other Id's
*)
V := 'BC50E0E8CA750D6F7524EC58B3071E9FCB4C8920';

(* create Certificate store object *)
Store := CoStore.Create;

(* open the My Store containing certs with private keys *)
Store.Open( CAPICOM_CURRENT_USER_STORE, 'MY', CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED );

(* find the certificate with the given thumbprint *)
vCertsLista := Store.Certificates as ICertificates2;

Certs := vCertsLista.Find(CAPICOM_CERTIFICATE_FIND_SHA1_HASH, V, False);

// Certs := Store.Certificates.Find(CAPICOM_CERTIFICATE_FIND_SHA1_HASH, V, False );

(* any certificates found? *)
if Certs.Count > 0 then
begin
(* get the certificate context *)
Cert := IInterface( Certs.Item[ 1 ] ) as ICertificate2;
CertContext := Cert as ICertContext;
CertContext.Get_CertContext( Integer( PCertContext ) );

(* set the certificate to use for the SSL connection *)
if InternetSetOption( Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT,
PCertContext, Sizeof( CERT_CONTEXT ) ) = False then
begin
raise Exception.Create('Erro ao configurar certificado para conexão SSL.');
end;
end;

end;

Please can anyone help me?
Many thanks!

Edited by: Chris Marisco on Mar 17, 2016 10:26 AM

Edited by: Chris Marisco on Mar 17, 2016 10:33 AM

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02