PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Como usar webservices #281955

17/05/2005

0

Pessoal,
preciso usar um webservices gerei a unit abaixo porém não sei como fazer funcionar:


// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://www.byjg.com.br/xmlnuke/webservice/cepservice.asmx?WSDL
// Encoding : utf-8
// Version  : 1.0
// (17/5/2005 10:16:01 - 1.33.2.5)
// ************************************************************************ //

unit cepservice;

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"
  // !:                - "http://www.byjg.com.br"

  ArrayOfAnyType       = class;                 { "http://www.byjg.com.br"[A] }

  anyType    = array of Variant;                { "http://www.byjg.com.br" }


  // ************************************************************************ //
  // Namespace : http://www.byjg.com.br
  // Serializtn: [xoInlineArrays]
  // ************************************************************************ //
  ArrayOfAnyType = class(TRemotable)
  private
    FanyType: anyType;
  public
    constructor Create; override;
    function   GetVariantArray(Index: Integer): Variant;
    function   GetVariantArrayLength: Integer;
    property   VariantArray[Index: Integer]: Variant read GetVariantArray; default;
    property   Len: Integer read GetVariantArrayLength;
  published
    property anyType: anyType read FanyType write FanyType;
  end;


  // ************************************************************************ //
  // Namespace : http://www.byjg.com.br
  // soapAction: http://www.byjg.com.br/¬operationName¬
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // binding   : ConsultaCEPSoap
  // service   : ConsultaCEP
  // port      : ConsultaCEPSoap
  // URL       : http://www.byjg.com.br/xmlnuke/webservice/cepservice.asmx
  // ************************************************************************ //
  ConsultaCEPSoap = interface(IInvokable)
  [´{27F8F6FA-71AC-B27A-F216-9F887FD4E868}´]
    function  obterLogradouro(const Cep: WideString): WideString; stdcall;
    function  obterCEP(const Logradouro: WideString; const Localidade: WideString; const UF: WideString): ArrayOfAnyType; stdcall;
    function  obterVersao: WideString; stdcall;
  end;

function GetConsultaCEPSoap(UseWSDL: Boolean=System.False; Addr: string=´´; HTTPRIO: THTTPRIO = nil): ConsultaCEPSoap;


implementation

function GetConsultaCEPSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ConsultaCEPSoap;
const
  defWSDL = ´http://www.byjg.com.br/xmlnuke/webservice/cepservice.asmx?WSDL´;
  defURL  = ´http://www.byjg.com.br/xmlnuke/webservice/cepservice.asmx´;
  defSvc  = ´ConsultaCEP´;
  defPrt  = ´ConsultaCEPSoap´;
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 ConsultaCEPSoap);
    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;


constructor ArrayOfAnyType.Create;
begin
  inherited Create;
  FSerializationOptions := [xoInlineArrays];
end;

function ArrayOfAnyType.GetVariantArray(Index: Integer): Variant;
begin
  Result := FanyType[Index];
end;

function ArrayOfAnyType.GetVariantArrayLength: Integer;
begin
  if Assigned(FanyType) then
    Result := Length(FanyType)
  else
  Result := 0;
end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(ConsultaCEPSoap), ´http://www.byjg.com.br´, ´utf-8´);
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ConsultaCEPSoap), ´http://www.byjg.com.br/¬operationName¬´);
  InvRegistry.RegisterInvokeOptions(TypeInfo(ConsultaCEPSoap), ioDocument);
  RemClassRegistry.RegisterXSInfo(TypeInfo(anyType), ´http://www.byjg.com.br´, ´anyType´);
  RemClassRegistry.RegisterXSClass(ArrayOfAnyType, ´http://www.byjg.com.br´, ´ArrayOfAnyType´);
  RemClassRegistry.RegisterSerializeOptions(ArrayOfAnyType, [xoInlineArrays]);

end.



Na minha aplicação inseri um componente THTTPRIO e no evento OnCreate do form coloquei o código:

var
  H : ConsultaCEPSoap;
begin
  showMessage(H.obterLogradouro(´88020-200´));
end;


Como fazer?


Carlosib

Carlosib

Responder

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

Aceitar