problemas de comunicação com Webservices

05/03/2010

4

Prezados,   Estou com problemas de comunicação com Webservices, na tentativa de fazer um acesso está me retornando o seguinte erro:     'System.Web.Services.Protocols.SoapException: Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/soap/envelope/ was unexpected. Expecting http://www.w3.org/2003/05/soap-envelope at System.Web.Services.Protocols.SoapServerProtocol.CheckHelperVersion()   at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)'
  Uso Delphi7

Rotina:

const
  INTERNET_OPTION_CLIENT_CERT_CONTEXT = 84;

procedure TFrmPrincipal.OnBeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
var
  Cert         : ICertificate2;
  CertContext  : ICertContext;
  PCertContext : Pointer;
begin
  Cert := Configuracoes.Certificados.GetCertificado;
  CertContext :=  Cert as ICertContext;
  CertContext.Get_CertContext(Integer(PCertContext));

  InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext,sizeof(CertContext)*5);
end;

procedure TFrmPrincipal.Button1Click(Sender: TObject);
var
  aMsg: string;
  Nota: CteStatusServicoSoap12;
  Rio: THTTPRIO;
  FURL, FRetWS : string;
begin

  FURL := 'https://homologacao.cte.sefaz.rs.gov.br/ws/ctestatusservico/ctestatusservico.asmx';

  Rio := THTTPRIO.Create(nil);
  Rio.HTTPWebNode.OnBeforePost := OnBeforePost;

  try
  
    Nota   := GetCteStatusServicoSoap12( False, FURL, Rio);
    FRetWS := Nota.cteStatusServicoCT('2STATUS');

  finally

    Rio.Free;
  end;
end;


Minha Interface:

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : C:\Documents and Settings\Administrador\Desktop\Teste_SOAP_CTe\temp\ctestatusservico.wsdl
// Encoding : utf-8
// Version  : 1.0
// (5/3/2010 15:36:59 - 1.33.2.5)
// ************************************************************************ //

unit ctestatusservico;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

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 Borland types; however, they could also
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:string          - "http://www.w3.org/2001/XMLSchema"



  // ************************************************************************ //
  // Namespace : http://www.portalfiscal.inf.br/cte/wsdl/CteStatusServico
  // binding   : CteStatusServicoSoap12
  // service   : CteStatusServico
  // port      : CteStatusServicoSoap12
  // ************************************************************************ //
  CteStatusServicoSoap12 = interface(IInvokable)
  ['{E75AF039-AF5D-31A0-9BD4-23E527E93890}']
    function  cteStatusServicoCT(const cteDadosMsg: WideString): WideString; stdcall;
  end;

function GetCteStatusServicoSoap12(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): CteStatusServicoSoap12;


implementation

function GetCteStatusServicoSoap12(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): CteStatusServicoSoap12;
const
  defWSDL = 'C:\Documents and Settings\Administrador\Desktop\Teste_SOAP_CTe\temp\ctestatusservico.wsdl';
  defURL  = '';
  defSvc  = 'CteStatusServico';
  defPrt  = 'CteStatusServicoSoap12';
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 CteStatusServicoSoap12);
    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
  InvRegistry.RegisterInterface(TypeInfo(CteStatusServicoSoap12), 'http://www.portalfiscal.inf.br/cte/wsdl/CteStatusServico', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(CteStatusServicoSoap12), '');

end.



Alguma sugestão?

Atenciosamente,
Bruno Figueira
Responder

Posts

05/03/2010

André Moraes.

O CTe usa soap 1.2 e apenas o Delphi 2010 é compatível com esta versão de soap.   Se vc usa uma versão anterior a 2010 do Delphi vc pode consumir o webservice usando o componente HTTPReqResp, veja nos fontes do componente ACBrCTe que vc encontrará um exemplo de como fazer.
Responder

05/03/2010

Bruno Figueira

Prezado André,

estou tentando uma alternativa com THTTPRio pois usando o THTTPReqResp do ACBrCTe na tentativa de enviar Lote de Recepcao do CTe, simplismente não me retorna resposta de nada (nem erro e nem confirmação).  O estranho é que o Status do Serviço pelo ACBrCTe (THTTPReqResp) responde corretamente.


Dados do meu exemplo xml de envio de Lote:  OBS (Não existe essas quebras de linha, apenas coloquei para demonstrar aqui no forum)

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<cteCabecMsg xmlns="http://www.portalfiscal.inf.br/cte/wsdl/CteStatusServico">
<cUF>33</cUF>
<versaoDados>1.03</versaoDados>
</cteCabecMsg>
</soap12:Header>
<soap12:Body>
<cteDadosMsg xmlns="http://www.portalfiscal.inf.br/cte/wsdl/CteStatusServico">

enviCTe versao="1.02">
<idLote>000000000007914</idLote>

<CTe>

<infCte Id="CTe43090343244631003770570000000000015246191849" versao="1.02">

<ide>
<cUF>43</cUF>
<cCT>524619184</cCT>
<CFOP>6353</CFOP>

<natOp>
PREST SERV TRANSP P/CONTR INTEREST(ESTABELECIMENTO)COMERCIAL
</natOp>
<forPag>1</forPag>
<mod>57</mod>
<serie>0</serie>
<nCT>1</nCT>
<dhEmi>2009-03-02T07:36:05</dhEmi>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>9</cDV>
<tpAmb>1</tpAmb>
<tpCTe>0</tpCTe>
<procEmi>0</procEmi>
<verProc>1.5</verProc>
<cMunEmi>4303103</cMunEmi>
<xMunEmi>CACHOEIRINHA</xMunEmi>
<UFEmi>RS</UFEmi>
<modal>01</modal>
<tpServ>0</tpServ>
<cMunIni>4303103</cMunIni>
<xMunIni>CACHOEIRINHA</xMunIni>
<UFIni>RS</UFIni>
<cMunFim>3151800</cMunFim>
<xMunFim>POCOS DE CALDAS</xMunFim>
<UFFim>MG</UFFim>
<retira>1</retira>

<toma03>
<toma>0</toma>
</toma03>
</ide>

<compl>
<xCaracAd>ENT. PLATAFORMA</xCaracAd>
<xEmi>RANASCIMENTO</xEmi>

<fluxo>
<xOrig>POA</xOrig>
<xDest>CPQ</xDest>
<xRota>016</xRota>
</fluxo>
<origCalc>CACHOEIRINHA</origCalc>
<destCalc>POCOS DE CALDAS</destCalc>

<xObs>
ISENCAO DO ICMS CONF. LIVRO I - TITULO II - ART.10, IX. DME060309-
</xObs>

<ObsCont xCampo="nro_contrato">
<xTexto>052285</xTexto>
</ObsCont>

<ObsCont xCampo="vigencia">
<xTexto>01/08/08</xTexto>
</ObsCont>

<ObsCont xCampo="tabela">
<xTexto>052285</xTexto>
</ObsCont>

<ObsCont xCampo="quebra">
<xTexto>0</xTexto>
</ObsCont>

<ObsCont xCampo="faturista">
<xTexto>1</xTexto>
</ObsCont>

<ObsCont xCampo="numerocte">
<xTexto>TA-038-000-000001</xTexto>
</ObsCont>

<ObsCont xCampo="codbarra">
<xTexto>814187684</xTexto>
</ObsCont>
</compl>

<emit>
<CNPJ>43244631003770</CNPJ>
<IE>001770145890</IE>
<xNome>TRANSPORTADORA AMERICANA</xNome>
<xFant>TA - PTA</xFant>

<enderEmit>
<xLgr>AV FREDERICO AUGUSTO RITTER, 4901</xLgr>
<nro>0</nro>
<xBairro>DT INDUSTRIAL</xBairro>
<cMun>4303103</cMun>
<xMun>CACHOEIRINHA</xMun>
<CEP>94930000</CEP>
<UF>RS</UF>
<cPais>1058</cPais>
<xPais>BRASIL</xPais>
<fone>5132055000</fone>
</enderEmit>
</emit>

<rem>
<CNPJ>94261534000115</CNPJ>
<IE>0720057744</IE>
<xNome>DOCILE ALIM LTDA</xNome>
<xFant>DOCILE</xFant>
<fone>5137262600</fone>

<enderReme>
<xLgr>ROD RS 130 - KM 70 SN CX POSTAL 555</xLgr>
<nro>0</nro>
<xBairro>MOINHOS</xBairro>
<cMun>4311403</cMun>
<xMun>LAJEADO</xMun>
<CEP>95900000</CEP>
<UF>RS</UF>
<cPais>1058</cPais>
<xPais>BRASIL</xPais>
</enderReme>

<infNF>
<serie>00</serie>
<nDoc>172319</nDoc>
<dEmi>2009-03-02</dEmi>
<vBC>979.78</vBC>
<vICMS>117.57</vICMS>
<vBCST>0</vBCST>
<vST>0</vST>
<vProd>979.78</vProd>
<vNF>1028.78</vNF>
<nCFOP>6101</nCFOP>
<nPeso>162.940</nPeso>
</infNF>
</rem>

<dest>
<CNPJ>05521012000185</CNPJ>
<IE>5182355370030</IE>
<xNome>HERMES RIBEIRO DE OLIVEIRA</xNome>

<enderDest>
<xLgr>RUA RIO GRANDE DO SUL, 791, LT A</xLgr>
<nro>0</nro>
<xBairro>CENTRO</xBairro>
<cMun>3151800</cMun>
<xMun>POCOS DE CALDAS</xMun>
<CEP>37701001</CEP>
<UF>MG</UF>
<cPais>1058</cPais>
<xPais>BRASIL</xPais>
</enderDest>
</dest>

<vPrest>
<vTPrest>98.14</vTPrest>
<vRec>98.14</vRec>

<Comp>
<xNome>FRETE PESO</xNome>
<vComp>75.42</vComp>
</Comp>

<Comp>
<xNome>DESPACHO</xNome>
<vComp>10.01</vComp>
</Comp>

<Comp>
<xNome>FRETE VALOR</xNome>
<vComp>2.57</vComp>
</Comp>

<Comp>
<xNome>GRIS</xNome>
<vComp>3.28</vComp>
</Comp>

<Comp>
<xNome>PEDAGIO</xNome>
<vComp>5.09</vComp>
</Comp>

<Comp>
<xNome>TAS</xNome>
<vComp>1.77</vComp>
</Comp>
</vPrest>

<imp>

<ICMS>

<CST45>
<CST>40</CST>
</CST45>
</ICMS>
</imp>

<infCTeNorm>

<infCarga>
<vMerc>1028.78</vMerc>
<proPred>ALIMENTOS</proPred>

<infQ>
<cUnid>01</cUnid>
<tpMed>PESO BRUTO</tpMed>
<qCarga>162.9400</qCarga>
</infQ>

<infQ>
<cUnid>01</cUnid>
<tpMed>PESO BASE CALCULO</tpMed>
<qCarga>162.9400</qCarga>
</infQ>

<infQ>
<cUnid>01</cUnid>
<tpMed>PESO AFERIDO</tpMed>
<qCarga>162.9400</qCarga>
</infQ>

<infQ>
<cUnid>03</cUnid>
<tpMed>QTDE DE VOLUMES</tpMed>
<qCarga>14</qCarga>
</infQ>
</infCarga>

<seg>
<respSeg>4</respSeg>
<xSeg>ACE SEGURADORA S. A.</xSeg>
<nApol>54-1639C</nApol>
<vMerc>1028.780</vMerc>
</seg>

<rodo>
<RNTRC>10082000197145</RNTRC>
<dPrev>2009-03-06</dPrev>
<lota>0</lota>
</rodo>
</infCTeNorm>
</infCte>

<Signature>

<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="#CTe43090343244631003770570000000000015246191849">

<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>mNZYnOqGngnvv1QoRg8ZWs3qAkQ=</DigestValue>
</Reference>
</SignedInfo>

<SignatureValue>
GjA0HYiVQm6QH6MOGc+KL1F58qKO+9MNHPsafrrqNJM3JwzKVuvzlIba4rdN23cQ4nT34DAKiFKskL+E3f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Bruno Figueira

Responder

11/03/2010

Ngm Systems

Certo, uso o ACBrNFe e ACBrCTe e baixei o Trial do Delphi 2010 para tentar resolver o problema de comunicação com o Web Service, porém não achei o SOAPHTTPClient para tentar executar a consulta no Web Service.   Quando tento a conexão com o ReqResp dá o retorno de Bad Request.   Como eu faço no Delphi 2010 para Executar a consulta no Web Service? Alguem pode me ajudar nisso?
Responder