GARANTIR DESCONTO

Fórum Consulta a cadastro Via WEBservice SEFAZ #414960

03/04/2012

0

Bom dia a todos.

Estou tentando desenvolver uma aplicação que faça a consulta a cadastro de contruibuintes pelo webservice da SEFAZ.
Estou com a seguinte dúvida:

Após ter consumido o webservice no delphi, não entendi como deverá ser usado o cabeçalho da mensagem do webservice, na unit criada pelo WSDL Importer não consegui entender muito bem onde que a mensagem do cabeçalho do webservice é informado ao webservice na hora de envio da mensagem do XML de consulta ao cadastro.

Abaixo segue a parte do código que fiz testes.



function TConsultaCadasstro.EnviaXML: WideString;
var
WebService: CadConsultaCadastro2Soap12;
w_ConsultaCadCab: nfeCabecMsg2;
w_XML: nfeDadosMsg;
w_XMLResult: consultaCadastro2Result;
w_XMLInt: WideString;
begin
inherited EnviaXML;
w_ConsultaCadCab := nfeCabecMsg2.Create;
w_XML := nfeDadosMsg.Create;
w_XMLResult := consultaCadastro2Result.Create;

w_ConsultaCadCab.cUF := 35;
w_ConsultaCadCab.versaoDados := 2.00;
WebService := GetCadConsultaCadastro2Soap12(False, https://homologacao.nfe.fazenda.sp.gov.br/nfeweb/services/CadConsultaCadastro2.asmx, Rio);

FCNPJ_CPF := TFString.TiraMascara2(FCNPJ_CPF);
FIE := TFString.TiraMascara2(FIE);


w_XMLInt := w_XMLInt + Trim(<ConsCad xmlns=http://www.portalfiscal.inf.br/nfe versao =2.00>);
w_XMLInt := w_XMLInt + Trim( <infCons>);
w_XMLInt := w_XMLInt + Trim( <xServ>CONS-CAD</xServ>);
w_XMLInt := w_XMLInt + Trim( <UF> + FUF + </UF>);

if (Trim(FIE) <> ) and (FIE <> ISENTO) and (FIE <> ISENTA) then
begin
w_XMLInt := w_XMLInt + Trim( <IE> + Trim(FIE) + </IE>);
end
else if (Trim(FCNPJ_CPF) <> ) and (Length(FCNPJ_CPF) > 12) then
begin
w_XMLInt := w_XMLInt + Trim( <CNPJ> + Trim(FCNPJ_CPF) + </CNPJ>);
end
else if (Trim(FCNPJ_CPF) <> ) then
begin
w_XMLInt := w_XMLInt + Trim( <CPF> + Trim(FCNPJ_CPF) + </CPF>);
end;

w_XMLInt := w_XMLInt + Trim( </infCons>);
w_XMLInt := w_XMLInt + Trim(</ConsCad>);

w_XML.LoadFromXML(w_XMLInt);


w_XMLResult := WebService.consultaCadastro2(w_XML);
Result := w_XMLResult.XMLNode.XML;
FreeAndNil(w_ConsultaCadCab);
FreeAndNil(w_XML);
FreeAndNil(w_XMLResult);
end;

Está dando a seguinte rejeição:
<cStat>242</cStat><xMotivo>Rejeição: Cabeçalho - Falha no Schema XML</xMotivo>

Se alguém já passou por isso ou sabe a solução agradeço desde já a atenção
Sistec Ltda

Sistec Ltda

Responder

Posts

27/04/2012

Rodrigo Chiarato

Olá.

Estou com o mesmo problema.
Você conseguiu resolver esta questão ?


O código esta abaixo:

unit CadconsultaCadastroSefazSP;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, 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[Lit][Gbl]
// !:string - http://www.w3.org/2001/XMLSchema[Gbl]

nfeCabecMsg2 = class; { http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2[Hdr][GblCplx] }
nfeCabecMsg = class; { http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2[Hdr][GblElm] }

consultaCadastro2Result = TXMLData; { http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2[Lit][GblElmMxd] }


// ************************************************************************ //
// XML : nfeCabecMsg, global, <complexType>
// Namespace : http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2
// Info : Header
// ************************************************************************ //
nfeCabecMsg2 = class(TSOAPHeader)
private
FcUF: string;
FcUF_Specified: boolean;
FversaoDados: string;
FversaoDados_Specified: boolean;
procedure SetcUF(Index: Integer; const Astring: string);
function cUF_Specified(Index: Integer): boolean;
procedure SetversaoDados(Index: Integer; const Astring: string);
function versaoDados_Specified(Index: Integer): boolean;
published
property cUF: string Index (IS_OPTN) read FcUF write SetcUF stored cUF_Specified;
property versaoDados: string Index (IS_OPTN) read FversaoDados write SetversaoDados stored versaoDados_Specified;
end;



// ************************************************************************ //
// XML : nfeCabecMsg, global, <element>
// Namespace : http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2
// Info : Header
// ************************************************************************ //
nfeCabecMsg = class(nfeCabecMsg2)
private
published
end;

nfeDadosMsg = TXMLData; { http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2[Lit][GblElmMxd] }

// ************************************************************************ //
// Namespace : http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2
// soapAction: http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2/consultaCadastro2
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// use : literal
// binding : CadConsultaCadastro2Soap12
// service : CadConsultaCadastro2
// port : CadConsultaCadastro2Soap12
// URL : https://nfe.fazenda.sp.gov.br/nfeweb/services/cadconsultacadastro2.asmx
// ************************************************************************ //
CadConsultaCadastro2Soap12 = interface(IInvokable)
[{06E5C4A8-175E-5B39-BB3B-1411D9C692BE}]

// Cannot unwrap:
// - Input element wrapper name does not match operations name
// - The output part is not a complex type
// Headers: nfeCabecMsg:pInOut

// function consultaCadastro2(const nfeDadosMsg: nfeDadosMsg): consultaCadastro2Result; stdcall;
function consultaCadastro2(const nfeDadosMsg: WideString): WideString; stdcall;
end;

function GetCadConsultaCadastro2Soap12(UseWSDL: Boolean=System.False; Addr: string=; HTTPRIO: THTTPRIO = nil): CadConsultaCadastro2Soap12;


implementation
uses SysUtils;

function GetCadConsultaCadastro2Soap12(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): CadConsultaCadastro2Soap12;
const
defWSDL = https://nfe.fazenda.sp.gov.br/nfeweb/services/cadconsultacadastro2.asmx?wsdl;
defURL = https://nfe.fazenda.sp.gov.br/nfeweb/services/cadconsultacadastro2.asmx;
defSvc = CadConsultaCadastro2;
defPrt = CadConsultaCadastro2Soap12;
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 CadConsultaCadastro2Soap12);
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;


procedure nfeCabecMsg2.SetcUF(Index: Integer; const Astring: string);
begin
FcUF := Astring;
FcUF_Specified := True;
end;

function nfeCabecMsg2.cUF_Specified(Index: Integer): boolean;
begin
Result := FcUF_Specified;
end;

procedure nfeCabecMsg2.SetversaoDados(Index: Integer; const Astring: string);
begin
FversaoDados := Astring;
FversaoDados_Specified := True;
end;

function nfeCabecMsg2.versaoDados_Specified(Index: Integer): boolean;
begin
Result := FversaoDados_Specified;
end;

initialization
{ CadConsultaCadastro2Soap12 }
InvRegistry.RegisterInterface(TypeInfo(CadConsultaCadastro2Soap12), http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2, utf-8);
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CadConsultaCadastro2Soap12), http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2/consultaCadastro2);
InvRegistry.RegisterInvokeOptions(TypeInfo(CadConsultaCadastro2Soap12), ioDocument);
InvRegistry.RegisterInvokeOptions(TypeInfo(CadConsultaCadastro2Soap12), ioLiteral);
InvRegistry.RegisterInvokeOptions(TypeInfo(CadConsultaCadastro2Soap12), ioSOAP12);
InvRegistry.RegisterHeaderClass(TypeInfo(CadConsultaCadastro2Soap12), nfeCabecMsg, nfeCabecMsg, http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2);
RemClassRegistry.RegisterXSInfo(TypeInfo(consultaCadastro2Result), http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2, consultaCadastro2Result);
RemClassRegistry.RegisterXSClass(nfeCabecMsg2, http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2, nfeCabecMsg2, nfeCabecMsg);
RemClassRegistry.RegisterXSClass(nfeCabecMsg, http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2, nfeCabecMsg);
RemClassRegistry.RegisterXSInfo(TypeInfo(nfeDadosMsg), http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2, nfeDadosMsg);

end.
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar